<?php

// Laravel
use Illuminate\Support\Facades\Route;

// Creatia
use App\Http\Controllers\Goliath\AdminGoliathController;
use App\Http\Controllers\Goliath\GoliathController;

class GoliathLevel2 {
    
    public static function routes() {
        static::user_view();
        static::user_edit();
        static::user_log();

        static::admin_view();
        static::admin_edit();
        static::admin_log();
    }

    /*
     * User Specific Routes
     */
    
    private static function user_view() {
        Route::group(['middleware' => ['auth:api', "bounce:goliath.l2.view"], 'prefix' => 'goliath'], function ($r) {
            
            // Get a list of all chains
            Route::get('/chain', [GoliathController::class, 'get_rulesets']);

            // Get list of chains attached to a prefix
            Route::get('/prefix/{_prefix_id}/chain', [GoliathController::class, 'get_rulesets'])->whereNumber('_prefix_id');

            // Get a list of prefixes attached to a chain
            Route::get('/chain/{_chain_id}/prefix/summary', [GoliathController::class, 'get_ruleset_prefixes'])->whereNumber('_chain_id');

            // Get an individual chain
            Route::get('/chain/{_chain_id}', [GoliathController::class, 'get_ruleset'])->whereNumber('_chain_id');
    
            // Get a list of prefixes attached to a chain
            Route::get('/chain/{_chain_id}/prefix', [GoliathController::class, 'get_ruleset_prefix_list'])->whereNumber('_chain_id');

            // Check whether a BPF rule is valid
            Route::get('/bpf', [GoliathController::class, 'get_valid_bpf']);

            // Check whether the ruleset meets costing
            Route::query('/ruleset/validity', [GoliathController::class, 'get_ruleset_validity']);

        });
    }

    private static function user_edit() {
        Route::group(['middleware' => ['auth:api', "bounce:goliath.l2.edit"], 'prefix' => 'goliath'], function ($r) {    

            // Get a list of options to use in editing
            Route::get('/chain/options', [GoliathController::class, 'get_ruleset_options']);
    
            // Create a new chain
            Route::post('/chain', [GoliathController::class, 'put_ruleset']);
    
            // Edit an existing chain
            Route::put('/chain/{_chain_id}', [GoliathController::class, 'put_ruleset'])->whereNumber('_chain_id');
    
            // Delete an existing chain
            Route::delete('/chain/{_chain_id}', [GoliathController::class, 'delete_ruleset'])->whereNumber('_chain_id');
    
            // Associate a chain with a prefix
            Route::put('/prefix/chain/{_prefix_id}', [GoliathController::class, 'put_prefix_ruleset'])->whereNumber('_prefix_id');
    
            // Disassociate a chain with a prefix
            Route::delete('/prefix/chain/{_prefix_id}', [GoliathController::class, 'delete_prefix_ruleset'])->whereNumber('_prefix_id');

        });
    }

    private static function user_log() {
        Route::group(['middleware' => ['auth:api', "bounce:goliath.l2.log"], 'prefix' => 'goliath'], function ($r) {

        });
    }

    /*
     * Admin Specific Routes
     */

    private static function admin_view() {
        Route::group(['middleware' => ['auth:api', "bounce:goliath.l2.manage,goliath.l1.view"], 'prefix' => 'admin/goliath'], function ($r) {
            
            // Get a list of all chains
            Route::get('/chain', [AdminGoliathController::class, 'get_rulesets']);

            // Get a list of chains attached to a prefix
            Route::get('/prefix/{_prefix_id}/chain', [AdminGoliathController::class, 'get_rulesets'])->whereNumber('_prefix_id');

            // Get a list of prefixes attached to a chain
            Route::get('/chain/{_chain_id}/prefix/summary', [AdminGoliathController::class, 'get_ruleset_prefixes'])->whereNumber('_chain_id');

            // Get an individual chain
            Route::get('/chain/{_chain_id}', [AdminGoliathController::class, 'get_ruleset'])->whereNumber('_chain_id');
    
            // Get a list of prefixes attached to a chain
            Route::get('/chain/{_chain_id}/prefix', [AdminGoliathController::class, 'get_ruleset_prefix_list'])->whereNumber('_chain_id');

            // Check whether the ruleset meets costing
            Route::query('/ruleset/validity', [GoliathController::class, 'get_ruleset_validity']);

        });
    }

    private static function admin_edit() {
        Route::group(['middleware' => ['auth:api', "bounce:goliath.l1.manage,goliath.l2.edit"], 'prefix' => 'admin/goliath'], function ($r) {
            
            // Get a list of options to use in editing
            Route::get('/chain/options', [AdminGoliathController::class, 'get_ruleset_options']);
            
            // Create a new chain
            Route::post('/chain', [AdminGoliathController::class, 'put_ruleset']);
    
            // Edit an existing chain
            Route::put('/chain/{_chain_id}', [AdminGoliathController::class, 'put_ruleset'])->whereNumber('_chain_id');
    
            // Delete an existing chain
            Route::delete('/chain/{_chain_id}', [AdminGoliathController::class, 'delete_ruleset'])->whereNumber('_chain_id');
    
            // Associate a chain with a prefix
            Route::put('/prefix/chain/{_prefix_id}', [AdminGoliathController::class, 'put_prefix_ruleset'])->whereNumber('_prefix_id');
    
            // Disassociate a chain with a prefix
            Route::delete('/prefix/chain/{_prefix_id}', [AdminGoliathController::class, 'delete_prefix_ruleset'])->whereNumber('_prefix_id');

        });
    }

    private static function admin_log() {
        Route::group(['middleware' => ['auth:api', "bounce:goliath.l1.manage,goliath.l2.log"], 'prefix' => 'admin/goliath'], function ($r) {
            
        });
    }

}
