<?php

use App\Modules\HR\Leave\Controllers\LeaveBalancesPageController;
use App\Modules\HR\Leave\Controllers\LeaveRequestsPageController;
use App\Modules\HR\Leave\Controllers\LeaveTypesPageController;
use Illuminate\Support\Facades\Route;

Route::prefix('hr/leave')->name('hr.leave.')->middleware('module:hr')->group(function () {
    Route::get('/types', [LeaveTypesPageController::class, 'index'])
        ->middleware('can:leave_types.view')
        ->name('types.index');
    Route::get('/types/create', [LeaveTypesPageController::class, 'create'])
        ->middleware('can:leave_types.create')
        ->name('types.create');
    Route::post('/types', [LeaveTypesPageController::class, 'store'])
        ->middleware('can:leave_types.create')
        ->name('types.store');
    Route::get('/types/{leave_type}/edit', [LeaveTypesPageController::class, 'edit'])
        ->middleware('can:leave_types.update,leave_type')
        ->name('types.edit');
    Route::put('/types/{leave_type}', [LeaveTypesPageController::class, 'update'])
        ->middleware('can:leave_types.update,leave_type')
        ->name('types.update');
    Route::post('/types/{leave_type}/deactivate', [LeaveTypesPageController::class, 'deactivate'])
        ->middleware('can:leave_types.deactivate,leave_type')
        ->name('types.deactivate');

    Route::get('/balances', [LeaveBalancesPageController::class, 'index'])
        ->middleware('can:leave.view')
        ->name('balances.index');

    Route::get('/requests', [LeaveRequestsPageController::class, 'index'])
        ->middleware('can:leave.view')
        ->name('requests.index');

    Route::get('/requests/create', [LeaveRequestsPageController::class, 'create'])
        ->middleware('can:leave.create')
        ->name('requests.create');

    Route::post('/requests', [LeaveRequestsPageController::class, 'store'])
        ->middleware('can:leave.create')
        ->name('requests.store');

    Route::post('/requests/{leaveRequest}/approve/manager', [LeaveRequestsPageController::class, 'approveManager'])
        ->whereNumber('leaveRequest')
        ->middleware('can:leave.approve.manager')
        ->name('requests.approve.manager');

    Route::post('/requests/{leaveRequest}/approve/hr', [LeaveRequestsPageController::class, 'approveHr'])
        ->whereNumber('leaveRequest')
        ->middleware('can:leave.approve.hr')
        ->name('requests.approve.hr');

    Route::post('/requests/{leaveRequest}/reject', [LeaveRequestsPageController::class, 'reject'])
        ->whereNumber('leaveRequest')
        ->middleware('can:leave.reject')
        ->name('requests.reject');

    Route::post('/requests/{leaveRequest}/cancel', [LeaveRequestsPageController::class, 'cancel'])
        ->whereNumber('leaveRequest')
        ->name('requests.cancel');
});
