<?php

use App\Middlewares\AdminMiddleware;
use App\Middlewares\AuthMiddleware;
use App\Middlewares\ComunityMiddleware;
use App\Middlewares\WorkerMiddleware;
use Core\Router;

$router = new Router();

// El usuario debe estar autenticado
$router->group([AuthMiddleware::class], function ($router) {

    $router->get('select-role', 'AuthController@selectRole');
    $router->post('set-role', 'AuthController@setRole');

    $router->get('dashboard', 'DashboardController@index');

    $router->get('get-procedure-details', 'ProcedureController@getProcedureDetails');

    //Ruta para trámites
    $router->get('processes/create', 'ProcessController@create');
    $router->post('processes', 'ProcessController@store');
    $router->get('processes/show-processes', 'ProcessController@showProcesses');
    $router->get('processes/{id}/show-process', 'ProcessController@showProcess');
    $router->get('processes/search', 'ProcessController@search');
    $router->post('processes/search-process', 'ProcessController@searchProcess');

    //Ruta para el perfil
    $router->get('profile', 'ProfileController@index');
    $router->post('profile/update', 'ProfileController@update');
    $router->post('profile/update-password', 'ProfileController@updatePassword');
    $router->post('profile/update-profile-picture', 'ProfileController@updatePicture');

    //Ruta para notificaciones
    $router->get('notifications/get', 'NotificationController@getNotifications');
    $router->post('notifications/clear', 'NotificationController@clearNotifications');

    //Ruta para subsanar trámites
    $router->get('processes/{id}/amend', 'ProcessController@amend');
    $router->put('processes/{id}/correct', 'ProcessController@correct');

    $router->get('logout', 'AuthController@logout');
});


// El usuario debe estar autenticado y tener el rol de ADMIN
$router->group([AuthMiddleware::class, AdminMiddleware::class], function ($router) {

    // Rutas para áreas
    $router->get('areas', 'AreaController@index');
    $router->get('areas/{id}', 'AreaController@show');
    $router->get('areas/create', 'AreaController@create');
    $router->get('areas/{id}/edit', 'AreaController@edit');
    $router->post('areas', 'AreaController@store');
    $router->put('areas/{id}/update', 'AreaController@update');
    $router->delete('areas/{id}/delete', 'AreaController@delete');
    $router->get('areas/{id}/show-groups', 'AreaController@groups');

    // Rutas para tipos de grupos
    $router->get('grouptypes', 'GroupTypeController@index');
    $router->get('grouptypes/{id}', 'GroupTypeController@show');
    $router->get('grouptypes/create', 'GroupTypeController@create');
    $router->get('grouptypes/{id}/edit', 'GroupTypeController@edit');
    $router->post('grouptypes', 'GroupTypeController@store');
    $router->put('grouptypes/{id}/update', 'GroupTypeController@update');
    $router->delete('grouptypes/{id}/delete', 'GroupTypeController@delete');
    $router->post('grouptypes/assign', 'GroupTypeController@assignGroupType');
    $router->delete('grouptypes/unassign', 'GroupTypeController@unassignGroupType');

    // Rutas para grupos
    $router->get('groups', 'GroupController@index');
    $router->get('groups/{id}', 'GroupController@show');
    $router->get('groups/create', 'GroupController@create');
    $router->get('groups/{id}/edit', 'GroupController@edit');
    $router->post('groups', 'GroupController@store');
    $router->put('groups/{id}/update', 'GroupController@update');
    $router->delete('groups/{id}/delete', 'GroupController@delete');

    // Rutas para subgrupos
    $router->get('subgroups', 'SubgroupController@index');
    $router->get('subgroups/{id}', 'SubgroupController@show');
    $router->get('subgroups/create', 'SubgroupController@create');
    $router->get('subgroups/{id}/edit', 'SubgroupController@edit');
    $router->post('subgroups', 'SubgroupController@store');
    $router->put('subgroups/{id}/update', 'SubgroupController@update');
    $router->delete('subgroups/{id}/delete', 'SubgroupController@delete');

    // Rutas para usuarios ugel
    $router->get('ugel-users', 'UserController@usersUgel');
    $router->get('users/create-ugel-user', 'UserController@createUserUgel');
    $router->post('ugel-users', 'UserController@storeUserUgel');
    $router->get('ugel-users/{id}/edit', 'UserController@editUserUgel');
    $router->put('ugel-users/{id}/update', 'UserController@updateUserUgel');
    $router->delete('ugel-users/{id}/delete', 'UserController@deleteUserUgel');

    // Rutas para usuarios comunidad
    $router->get('comunity-users', 'UserController@usersComunity');
    $router->get('comunity-users/{id}/edit', 'UserController@editUserComunity');
    $router->put('comunity-users/{id}/update', 'UserController@updateUserComunity');
    $router->delete('comunity-users/{id}/delete', 'UserController@deleteUserComunity');

    // Rutas para tipos de persona
    $router->get('persontypes', 'PersonTypeController@index');
    $router->get('persontypes/{id}', 'PersonTypeController@show');
    $router->get('persontypes/create', 'PersonTypeController@create');
    $router->get('persontypes/{id}/edit', 'PersonTypeController@edit');
    $router->post('persontypes', 'PersonTypeController@store');
    $router->put('persontypes/{id}/update', 'PersonTypeController@update');
    $router->delete('persontypes/{id}/delete', 'PersonTypeController@delete');

    // Rutas para modalidades
    $router->get('modalities', 'ModalityController@index');
    $router->get('modalities/{id}', 'ModalityController@show');
    $router->get('modalities/create', 'ModalityController@create');
    $router->get('modalities/{id}/edit', 'ModalityController@edit');
    $router->post('modalities', 'ModalityController@store');
    $router->put('modalities/{id}/update', 'ModalityController@update');
    $router->delete('modalities/{id}/delete', 'ModalityController@delete');

    // Rutas para tipos de respuesta
    $router->get('responsetypes', 'ResponseTypeController@index');
    $router->get('responsetypes/{id}', 'ResponseTypeController@show');
    $router->get('responsetypes/create', 'ResponseTypeController@create');
    $router->get('responsetypes/{id}/edit', 'ResponseTypeController@edit');
    $router->post('responsetypes', 'ResponseTypeController@store');
    $router->put('responsetypes/{id}/update', 'ResponseTypeController@update');
    $router->delete('responsetypes/{id}/delete', 'ResponseTypeController@delete');

    // Rutas para procedimientos
    $router->get('procedures', 'ProcedureController@index');
    $router->get('procedures/{id}', 'ProcedureController@show');
    $router->get('procedures/create', 'ProcedureController@create');
    $router->get('procedures/{id}/edit', 'ProcedureController@edit');
    $router->post('procedures', 'ProcedureController@store');
    $router->put('procedures/{id}/update', 'ProcedureController@update');
    $router->delete('procedures/{id}/delete', 'ProcedureController@delete');

    $router->get('procedures-route/{id}', 'ProcedureController@showRoute');
    $router->post('procedures-route/{id}/add', 'ProcedureController@storeStep');
    $router->get('procedures-route/{id}/edit', 'ProcedureController@editStep');
    $router->put('procedures-route/{id}/update', 'ProcedureController@updateStep');
    $router->delete('procedures-route/{id}/delete', 'ProcedureController@deleteStep');

    // Rutas para estados
    $router->get('states', 'StateController@index');
    $router->get('states/{id}', 'StateController@show');
    $router->get('states/create', 'StateController@create');
    $router->get('states/{id}/edit', 'StateController@edit');
    $router->post('states', 'StateController@store');
    $router->put('states/{id}/update', 'StateController@update');
    $router->delete('states/{id}/delete', 'StateController@delete');

    // Rutas para configuraciiones básicas
    $router->get('settings', 'SettingController@index');
    $router->get('settings/{id}', 'SettingController@show');
    $router->get('settings/create', 'SettingController@create');
    $router->get('settings/{id}/edit', 'SettingController@edit');
    $router->post('settings', 'SettingController@store');
    $router->put('settings/{id}/update', 'SettingController@update');
    $router->delete('settings/{id}/delete', 'SettingController@delete');

    $router->get('settings/expedient-counters', 'SettingController@indexExpedientCounter');
    $router->post('settings/expedient-counters/update', 'SettingController@updateExpedientCounter');
    $router->post('settings/expedient-counters/reset', 'SettingController@resetExpedientCounters');

    // Rutas para feriados
    $router->get('holidays', 'HolidayController@index');
    $router->get('holidays/{id}', 'HolidayController@show');
    $router->get('holidays/create', 'HolidayController@create');
    $router->get('holidays/{id}/edit', 'HolidayController@edit');
    $router->post('holidays', 'HolidayController@store');
    $router->put('holidays/{id}/update', 'HolidayController@update');
    $router->delete('holidays/{id}/delete', 'HolidayController@delete');
});

// El usuario debe estar autenticado y ser un trabajador
$router->group([AuthMiddleware::class, WorkerMiddleware::class], function ($router) {
    $router->get('processes/{id}/derive', 'ProcessController@deriveProcess');
    $router->post('processes-derive', 'ProcessController@storeDerive');
    $router->post('processes/{id}/accept-process', 'ProcessController@storeAcceptance');
    $router->post('processes/accept-all', 'ProcessController@storeAcceptanceAll');
    $router->get('processes/{id}/respond', 'ProcessController@respond');
    $router->post('processes/respond', 'ProcessController@storeResponse');

    $router->get('buscar-administrado', 'UserController@searchUser');
    $router->get('buscar-administrado-nombre', 'UserController@searchUserByName');
    $router->post('registrar-administrado', 'UserController@registerUser');

    //Rutas para el módulo de búsqueda
    $router->get('search', 'SearchController@index');
    $router->post('search/handle', 'SearchController@search');

    $router->post('search/name', 'SearchController@searchByName');
    $router->post('search/dni', 'SearchController@searchByDni');
    $router->post('search/dates', 'SearchController@searchByDateRange');
    $router->post('search/priority', 'SearchController@searchByPriority');
    $router->post('search/procedure', 'SearchController@searchByProcedure');
    $router->post('search/derivados', 'SearchController@searchByDerivationDate');

    //Ruta para los reportes
    $router->post('report/generate', 'ReportController@generate');

    $router->get('voucher/{id}/print', 'VoucherController@printVoucher');

    $router->post('processes/update-procedure/{id}', 'ProcessController@updateProcedure');
});


// El usuario debe estar autenticado y tener el rol de COMUNITY
$router->group([AuthMiddleware::class, ComunityMiddleware::class], function ($router) {

    //Rutas para selección del tipo de persona
    $router->get('select-person-type', 'AuthController@selectPersonType');
    $router->post('set-person-type', 'AuthController@setPersonType');

    //Rutas para la bandeja electrónica
    $router->get('inbox', 'InboxController@index');
    $router->get('inbox/{id}/show', 'InboxController@show');
    $router->post('register-download', 'InboxController@registerDownload');

    $router->get('processes/my-processes', 'ProcessController@myProcesses');
    $router->get('processes/my-resolutions', 'ProcessController@showResolvedProcesses');
});

$router->get('users/create-comunity-user', 'UserController@createUserComunity');
$router->post('comunity-users', 'UserController@storeUserComunity');
$router->get('search-comunity-user', 'UserController@searchComunityUser');

// Rutas de login
$router->get('', 'AuthController@loginForm');
$router->post('login', 'AuthController@login');

// Rutas para recuperar cuenta
$router->get('auth/forgot-password', 'AuthController@showForgotPasswordForm');
$router->post('auth/send-reset-code', 'AuthController@sendResetCode');
$router->post('auth/resend-reset-code', 'AuthController@resendResetCode');
$router->get('auth/reset-password', 'AuthController@showResetPasswordForm');
$router->post('auth/reset-password', 'AuthController@resetPassword');

// Rutas para el registro de usuarios
$router->get('auth/register', 'RegisterController@registerStep1');
$router->post('auth/register-step1', 'RegisterController@handleRegisterStep1');
$router->get('auth/verify-sent', 'RegisterController@showVerificationNotice');
$router->get('auth/verify-email', 'RegisterController@verifyEmail');
$router->get('auth/register-step2', 'RegisterController@registerStep2');
$router->post('auth/register-step2', 'RegisterController@handleRegisterStep2');
$router->post('auth/resend-verification', 'RegisterController@resendVerification');
