<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Applience\ApplienceController;
use App\Http\Controllers\DepartmentController;
use App\Http\Controllers\RequestController;
use App\Http\Controllers\AccessManagerController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\UserController;



/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Auth::routes();

Route::middleware(['auth'])->group(function () {
    Route::get('/', function () { return view('home'); });
    Route::get('/home', function () { return view('home'); });

    Route::middleware(['role:1'])->group(function () {
        Route::get ('/admin-manager',               [AdminController::class, 'show']);
        Route::get ('/admin-manager/load',          [AdminController::class, 'loadAdmins']);
        Route::post('/admin-manager/new',           [AdminController::class, 'saveAdmin']);
        Route::post('/admin-manager/edit/{ID}',     [AdminController::class, 'editAdmin']);
        Route::post('/admin-manager/delete/{ID}',   [AdminController::class, 'deleteAdmin']);
    });

    Route::middleware(['role:1,2,3'])->group(function () {
        Route::get  ('/users-manager',                      [UserController::class, 'show']);
        Route::get  ('/users-manager-load',                 [UserController::class, 'loadUsers']);
        Route::post ('/users-manager-new-user',             [UserController::class, 'saveNewUser']);
        Route::get  ('/users-manager-load/amount/{amount}',        [UserController::class, 'loadUsersByAmount']);

        Route::post ('/users-manager/delete/{ID}',             [UserController::class, 'deleteUser']);
        Route::get  ('/users-manager/info/{ID}',               [UserController::class, 'detailsUser']);
        Route::post ('/users-manager/edit/{ID}',               [UserController::class, 'editUser']);
    });

    Route::middleware(['role:1,2'])->group(function () {
        Route::get ('/access-manager',                                                      [AccessManagerController::class, 'show']);
        Route::get ('/access-manager/unfinished',                                           [AccessManagerController::class, 'unfinished']);
        Route::get ('/access-manager-requests',                                             [AccessManagerController::class, 'loadRequests']);
        Route::get ('/access-manager-process-usser/{userId}',                               [AccessManagerController::class, 'processUser']);
        Route::get ('/access-manager-process-usser/{userId}/load-tools',                    [AccessManagerController::class, 'loadUserTools']);
        Route::post('/access-manager-process-usser/{userId}/tool-access/{toolId}',          [AccessManagerController::class, 'createToolAcess']);


        Route::post('/access-manager/delete-tool-setup/{ID}',          [AccessManagerController::class, 'deleteTool']);
    });

    /*
    Route::middleware(['role:1,3'])->group(function () {
        Route::get('/request-manager',                                  [RequestController::class, 'show']);
        Route::get('/request-manager-load',                             [RequestController::class, 'load']);
        Route::post('/request-manager-reject/{id}',                     [RequestController::class, 'reject']);
        Route::post('/request-manager-process/{id}',                    [RequestController::class, 'process']);
        Route::post('/request-manager-assing-department/{id}',          [RequestController::class, 'assingDepartment']);
    });*/

    Route::middleware(['role:1,2'])->group(function () {
        Route::get  ('/role-manager',                                    [DepartmentController::class, 'show']);
        Route::post ('/role-manager',                                    [DepartmentController::class, 'new']);
        Route::get  ('/role-manager-load',                               [DepartmentController::class, 'load']);
        Route::get  ('/role-manager-load-tools',                         [DepartmentController::class, 'loadTools']);
        Route::get  ('/role-manager-load-nodefault-tools',               [DepartmentController::class, 'loadNodefaultTools']);
        Route::get  ('/role-manager-load-tools-roles',                   [DepartmentController::class, 'loadToolsRoles']);
        Route::get  ('/role-manager-load-job-roles/{roleID}/tools',      [DepartmentController::class, 'loadJobRoleTools']);

        
        Route::get  ('/role-manager/role/{roleID}',                      [DepartmentController::class, 'loadRoleDetails']);
        Route::post ('/role-manager/edit/{roleID}',                      [DepartmentController::class, 'editRole']);
        Route::post ('/role-manager/delete/{roleID}',                    [DepartmentController::class, 'deleteRole']);
        
        Route::get  ('/role-manager/tool/info/{ID}',                     [DepartmentController::class, 'loadToolDetails']);
        Route::post ('/role-manager/tool/delete/{ID}',                   [DepartmentController::class, 'deleteTool']);
        Route::post ('/role-manager/tool/edit/{ID}',                     [DepartmentController::class, 'editTool']);
        

        Route::post ('/tool-new',                                        [DepartmentController::class, 'newTool']);
    });

    Route::middleware(['role:4'])->group(function () {
        Route::get('/user', function () { dd('user route'); });
    });
});


Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('/login', [LoginController::class, 'login']);

Route::get ('/appliance-form', [ApplienceController::class, 'showForm'])->name('showApplianceForm');
Route::post('/appliance-form', [ApplienceController::class, 'applyForm']);

Route::get ('/user/activate/{userId}/{randString}', [UserController::class, 'activateAccountView']);
Route::post('/user/activate/{userId}/{randString}', [UserController::class, 'activateAccount']);
