<?php

use App\Http\Controllers\Admin\PermissionManagementController;
use App\Http\Controllers\Admin\RoleManagementController;
use App\Http\Controllers\Admin\UserManagementController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\CallController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\HeadquartersDashboard\LoginToProvinceController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\ProvinceController;
use App\Http\Controllers\HeadquartersDashboard\CumulativeCentersStatsController;
use App\Http\Controllers\HeadquartersDashboard\CumulativeKeypressStatsController;
use App\Http\Controllers\HeadquartersDashboard\CumulativeMessageRatingStatsController;
use App\Http\Controllers\HeadquartersDashboard\CumulativeVoiceRatingStatsController;
use App\Http\Controllers\ProvinceDashboard\VerifyAuthenticationController;
use App\Http\Middleware\SuperAdminCheck;
use Illuminate\Support\Facades\Route;

Route::prefix('server')->group(function () {
    Route::prefix('auth')
        ->name('auth.')
        ->controller(AuthController::class)
        ->group(function () {
            Route::post('/login', 'login')->name('login');
            Route::post('/logout', 'logout')->name('logout');
        });

    Route::prefix('profile')
        ->name('profile.')
        ->middleware('auth')
        ->controller(ProfileController::class)
        ->group(function () {
            Route::get('/info', 'info')->name('info');
            Route::post('/change_password', 'changePassword')->name('changePassword');
            Route::post('/change_avatar', 'changeAvatar')->name('changeAvatar');
            Route::get('/permissions', 'permissions')->name('permissions');
        });

    Route::prefix('users')
        ->name('users.')
        ->middleware(['auth', 'permission:manage_users'])
        ->controller(UserManagementController::class)
        ->group(function () {
            Route::get('/', 'index')->name('index');
            Route::get('/{user}', 'show')->middleware([SuperAdminCheck::class])->name('show');
            Route::post('/', 'store')->name('store');
            Route::post('/{user}', 'update')->middleware([SuperAdminCheck::class])->name('update');
            Route::delete('/{user}', 'destroy')->middleware([SuperAdminCheck::class])->name('destroy');
        });

    Route::prefix('calls')
        ->name('calls.')
        ->controller(CallController::class)
        ->group(function () {
            Route::post('/', 'store')->name('store');
            Route::get('/list', 'list')->name('list')->middleware(['auth', 'permission:manage_calls']);
            Route::post('/{call}', 'update')->name('update')->middleware(['auth', 'permission:manage_calls']);
        });

    Route::prefix('categories')
        ->middleware('auth')
        ->controller(CategoryController::class)
        ->name('categories.')
        ->group(function () {
            Route::get('/list', 'list')->name('list');
        });

    Route::middleware('auth')
        ->prefix('permissions')
        ->name('permissions.')
        ->controller(PermissionManagementController::class)
        ->group(function () {
            Route::get('/', 'index')->name('index');
            Route::get('list', 'list')->name('list');
            Route::post('/', 'store')->name('store');
            Route::get('/{permission}', 'show')->name('show');
            Route::post('/{permission}', 'update')->name('update');
            Route::delete('/{permission}', 'destroy')->name('destroy');
    });

    Route::prefix('provinces')
        ->controller(ProvinceController::class)
        ->name('provinces.')
        ->group(function () {
            Route::get('/list', 'list')->name('list');
        });

    Route::middleware('auth')
        ->prefix('roles')
        ->name('roles.')
        ->controller(RoleManagementController::class)
        ->group(function () {
            Route::get('/', 'index')->name('index');
            Route::get('list', 'list')->name('list');
            Route::post('/', 'store')->name('store');
            Route::get('/{role}', 'show')->name('show');
            Route::post('/{role}', 'update')->name('update');
            Route::delete('/{role}', 'destroy')->name('destroy');
        });

    Route::middleware('auth')
        ->prefix('cumulative_stats')
        ->name('cumulativeStats.')
        ->controller(CumulativeCentersStatsController::class)
        ->group(function () {
            Route::get('/', 'index')->name('index');
        });

    Route::middleware('auth')
        ->prefix('cumulative_voice_ratings')
        ->name('cumulativeVoiceRatings.')
        ->controller(CumulativeVoiceRatingStatsController::class)
        ->group(function () {
            Route::get('/', 'index')->name('index');
        });

    Route::middleware('auth')
        ->prefix('cumulative_keypress_stats')
        ->name('cumulativeKeypressStats.')
        ->controller(CumulativeKeypressStatsController::class)
        ->group(function () {
            Route::get('/', 'index')->name('index');
        });

    Route::middleware('auth')
        ->prefix('cumulative_message_ratings')
        ->name('cumulativeMessageRatings.')
        ->controller(CumulativeMessageRatingStatsController::class)
        ->group(function () {
            Route::get('/', 'index')->name('index');
        });
    Route::middleware('auth')
        ->prefix('dialogs')
        ->name('dialogs.')
        ->group(function () {
            Route::prefix('operator')
                ->name('operator.')
                ->controller(\App\Http\Controllers\ProvinceDashboard\OperatorDialogues\OperatorController::class)
                ->group(function () {
                    Route::get('/', 'index')->name('index');
                    Route::get('/excel', 'excel')->name('excel');
                    Route::get('/{operatorDialogue','show')->name('show');


                });
            Route::prefix('supervisor')
                ->name('supervisor.')
                ->controller(\App\Http\Controllers\ProvinceDashboard\OperatorDialogues\SupervisorController::class)
                ->group(function () {
                    Route::get('/', 'index')->name('index');
                    Route::get('/excel', 'excel')->name('excel');
                    Route::post('/rate/{operatorDialogue}', 'rate')->name('rate');
                    Route::get('/{operatorDialogue}', 'show')->name('show');

                });
        });

    Route::middleware('auth')
        ->prefix('system_messages')
        ->name('systemMessages.')
        ->group(function () {
            Route::prefix('operator')
                ->name('systemMessages.')
                ->controller(\App\Http\Controllers\ProvinceDashboard\SystemMessages\OperatorController::class)
                ->group(function () {
                    Route::get('/', 'index')->name('index');
                    Route::get('/excel', 'excel')->name('excel');
                    Route::get('/{systemMessage}', 'show')->name('show');
                });

            Route::prefix('supervisor')
                ->name('systemMessages.')
                ->controller(\App\Http\Controllers\ProvinceDashboard\SystemMessages\SupervisorController::class)
                ->group(function () {
                    Route::get('/', 'index')->name('index');
                    Route::get('/excel', 'excel')->name('excel');
                    Route::get('/{systemMessage}', 'show')->name('show');
                    Route::post('/{systemMessage}', 'rate')->name('rate');
                });
        });

    Route::middleware('auth')
        ->prefix('people_messages')
        ->name('peopleMessages.')
        ->group(function () {
            Route::prefix('operator')
                ->name('peopleMessages.')
                ->controller(\App\Http\Controllers\ProvinceDashboard\PeopleMessages\OperatorController::class)
                ->group(function () {
                    Route::get('/', 'index')->name('index');
                    Route::get('/excel', 'excel')->name('excel');
                    Route::post('/{peopleMessage}', 'handle')->name('handle');
                    Route::get('/{peopleMessage}', 'show')->name('show');
                });

            Route::prefix('supervisor')
                ->name('peopleMessages.')
                ->controller(\App\Http\Controllers\ProvinceDashboard\PeopleMessages\SupervisorController::class)
                ->group(function () {
                    Route::get('/', 'index')->name('index');
                    Route::get('/excel', 'excel')->name('excel');
                    Route::get('/{peopleMessage}', 'show')->name('show');
                });
        });

    Route::middleware(['auth', 'role:admin'])
        ->prefix('login_to_province')
        ->name('loginToProvince.')
        ->controller(LoginToProvinceController::class)
        ->group(function () {
            Route::post('/', 'authenticate')->name('authenticate');
        });

    Route::middleware(['auth', 'setadIp'])
        ->prefix('verify_authentication')
        ->name('verifyAuthentication.')
        ->controller(VerifyAuthenticationController::class)
        ->group(function () {
            Route::get('/', 'login')->name('login');
        });
});
