<?php

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

// Creatia
use App\Http\Controllers\Goliath\AdminReportController;
use App\Http\Controllers\Goliath\ReportController;

class GoliathReport {
    
    public static function routes() {
        static::guest_report();
        static::user_report();
        static::admin_report();
    }

    private static function guest_report() {
        Route::group(['middleware' => ['api'], 'prefix' => 'guest'], function ($r) {
    
            // Login
            Route::get('/report/download/{_token}', [ReportController::class, 'fetch_from_link']);
        
        });
    }

    private static function user_report() {

        Route::group(['middleware' => ['auth:api', "bounce:goliath.l1.report"], 'prefix' => 'goliath/report'], function ($r) {

            /*
             *  List Endpoints
             */

            //Route::get('/carpet', [ReportController::class, 'fetch_carpet']);
            Route::get('/single', [ReportController::class, 'fetch_single']);
            //Route::get('/period/{_type}', [ReportController::class, 'fetch_period'])->where([ '_type' => 'quarterly|monthly|weekly|daily' ]);

            /*
             * Report Fetching Endpoints
             */

            Route::get('/single/{_report_id}', [ReportController::class, 'report_single'])->where([ '_report_id' => '[0-9]+' ]);
            //Route::get('/carpet/{_report_id}', [ReportController::class, 'report_carpet'])->where([ '_report_id' => '[0-9]+' ]);
            //Route::get('/period/{_year}/{_type}/{_period}', [ReportController::class, 'report_period'])->where([ '_type' => 'quarterly|monthly|weekly|daily', '_year' => '[0-9]+', '_period' => '[0-9]+' ]);


            /*
             * Action endpoints
             */

            Route::get('/settings', [ReportController::class, 'fetch_attributes']);
            Route::post('/settings', [ReportController::class, 'set_attributes']);


        });

    }

    private static function admin_report() {

        Route::group(['middleware' => ['auth:api', "bounce:goliath.l1.manage,goliath.l1.report"], 'prefix' => 'admin/goliath/report'], function ($r) {

            /*
             *  List Endpoints
             */

            // Standard report lists
            Route::get('/carpet', [AdminReportController::class, 'fetch_carpet']);
            Route::get('/single', [AdminReportController::class, 'fetch_single']);
            Route::get('/period/{_type}', [AdminReportController::class, 'fetch_period'])->where([ '_type' => 'quarterly|monthly|weekly|daily' ]);

            // Approval related
            Route::get('/notification', [AdminReportController::class, 'fetch_notifications']);

            /*
             * Report Fetching Endpoints
             */

            // Standard report fetching
            Route::get('/carpet/{_report_id}', [AdminReportController::class, 'report_carpet'])->where([ '_report_id' => '[0-9]+' ]);
            Route::get('/single/{_report_id}', [AdminReportController::class, 'report_single'])->where([ '_report_id' => '[0-9]+' ]);
            Route::get('/period/{_year}/{_type}/{_period}', [AdminReportController::class, 'report_period'])->where([ '_type' => 'quarterly|monthly|weekly|daily', '_year' => '[0-9]+', '_period' => '[0-9]+' ]);

            /*
             * Action endpoints
             */

            // Settings
            Route::get('/attributes/{_organisation_id}', [AdminReportController::class, 'fetch_attributes']);
            Route::post('/attributes/{_organisation_id}', [AdminReportController::class, 'fetch_attributes']);

            /**
             * Updated refactor endpoints
             */

            Route::get('/leaderboard', [AdminReportController::class, 'fetch_leaderboard']);
        });

    }
}
