<?php

use App\Modules\HR\Overtime\Controllers\OvertimeRatePolicyPageController;
use App\Modules\HR\Overtime\Controllers\OvertimeRequestsPageController;
use Illuminate\Support\Facades\Route;

Route::prefix('hr/overtime')
    ->name('hr.overtime.')
    ->middleware('module:hr')
    ->group(function () {
        Route::get('/', [OvertimeRequestsPageController::class, 'index'])
            ->middleware('can:overtime.view')
            ->name('index');
        Route::get('/create', [OvertimeRequestsPageController::class, 'create'])
            ->middleware('can:overtime.create')
            ->name('create');
        Route::post('/', [OvertimeRequestsPageController::class, 'store'])
            ->middleware('can:overtime.create')
            ->name('store');
        Route::post('/{overtimeRequest}/approve', [OvertimeRequestsPageController::class, 'approve'])
            ->whereNumber('overtimeRequest')
            ->middleware('can:overtime.review')
            ->name('approve');
        Route::post('/{overtimeRequest}/reject', [OvertimeRequestsPageController::class, 'reject'])
            ->whereNumber('overtimeRequest')
            ->middleware('can:overtime.review')
            ->name('reject');
        Route::post('/{overtimeRequest}/cancel', [OvertimeRequestsPageController::class, 'cancel'])
            ->whereNumber('overtimeRequest')
            ->name('cancel');

        Route::prefix('rates')->name('rates.')->group(function () {
            Route::get('/', [OvertimeRatePolicyPageController::class, 'index'])
                ->middleware('can:overtime.view')
                ->name('index');
            Route::get('/create', [OvertimeRatePolicyPageController::class, 'create'])
                ->middleware('can:overtime.rates.manage')
                ->name('create');
            Route::post('/', [OvertimeRatePolicyPageController::class, 'store'])
                ->middleware('can:overtime.rates.manage')
                ->name('store');
            Route::get('/{policy}/edit', [OvertimeRatePolicyPageController::class, 'edit'])
                ->whereNumber('policy')
                ->middleware('can:overtime.rates.manage')
                ->name('edit');
            Route::put('/{policy}', [OvertimeRatePolicyPageController::class, 'update'])
                ->whereNumber('policy')
                ->middleware('can:overtime.rates.manage')
                ->name('update');
            Route::post('/{policy}/deactivate', [OvertimeRatePolicyPageController::class, 'deactivate'])
                ->whereNumber('policy')
                ->middleware('can:overtime.rates.manage')
                ->name('deactivate');
            Route::post('/{policy}/reactivate', [OvertimeRatePolicyPageController::class, 'reactivate'])
                ->whereNumber('policy')
                ->middleware('can:overtime.rates.manage')
                ->name('reactivate');
        });
    });
