<?php

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

// Creatia
use App\Http\Controllers\Locus\AdminGeoIpController;
use App\Http\Controllers\Locus\GeoIpController;
use App\Http\Controllers\Network\NetworkController;

class Locus {
    
    public static function routes() {

        static::user_view();
        static::user_add();
        static::user_edit();

        static::admin_view();

    }

    public static function user_view() {
 
        Route::group(['middleware' => ['auth:api', 'bounce:geoip.view'], 'prefix' => 'locus'], function ($r) {
                        
            // Fetch supernets
            Route::get('/prefix', [GeoIpController::class, 'get_geoips']);
            
            // Fetch subnets
            Route::get('prefix/{_geo_ip_id}', [GeoIpController::class, 'get_geoips'])->whereNumber('_geo_ip_id');
            
            // Get subnet metadata
            Route::get('prefix/{_geo_ip_id}/summary', [GeoIpController::class, 'get_geoip_metadata']);
            
            // Get metadata
            Route::get('prefix/summary', [GeoIpController::class, 'get_metadata']);

            // Get Regions
            Route::get('/region', [GeoIpController::class, 'get_regions']);
            
        });
    }

    public static function user_add() {
 
        Route::group(['middleware' => ['auth:api', 'bounce:geoip.add'], 'prefix' => 'locus'], function ($r) {
                        
            // Check if you can add the subnet
            Route::get('prefix/{_geo_ip_id}/subnet', [NetworkController::class, 'get_inside_subnet']);

            // Add the subnet
            Route::post('prefix/{_geo_ip_id}/subnet', [GeoIpController::class, 'post_subnet']);
            
        });
    }

    public static function user_edit() {
 
        Route::group(['middleware' => ['auth:api', 'bounce:geoip.edit'], 'prefix' => 'locus'], function ($r) {

            // Check if the edit values are valid
            Route::get('prefix/{_geo_ip_id}/data', [GeoIpController::class, 'get_data']);

            // Check if you can add the subnet
            Route::put('prefix/{_geo_ip_id}/data', [GeoIpController::class, 'put_data']);
            
        });
    }

    public static function admin_view() {
 
        Route::group(['middleware' => ['auth:api', 'bounce:geoip.view,management.view'], 'prefix' => 'admin/locus'], function ($r) {

            // Get history
            Route::get('/prefix/{_geo_ip_id}/history', [AdminGeoIpController::class, 'get_history']);
            
        });
    }
    
}
