<?php

use App\Modules\HR\Attendance\Controllers\AttendanceCorrectionRequestsPageController;
use App\Modules\HR\Attendance\Controllers\AttendanceImportController;
use App\Modules\HR\Attendance\Controllers\AttendanceExceptionsPageController;
use App\Modules\HR\Attendance\Controllers\AttendanceMonthlyReportPageController;
use App\Modules\HR\Attendance\Controllers\AttendanceRecordsPageController;
use App\Modules\HR\Attendance\Controllers\BiometricDevicesPageController;
use App\Modules\HR\Attendance\Controllers\BiometricLogIngestController;
use App\Modules\HR\Attendance\Controllers\HolidayController;
use Illuminate\Support\Facades\Route;

Route::prefix('hr/attendance')->name('hr.attendance.')->middleware('module:hr')->group(function () {
    Route::get('/holidays', [HolidayController::class, 'index'])->middleware('can:attendance.view')->name('holidays.index');
    Route::post('/holidays', [HolidayController::class, 'store'])->middleware('can:attendance.manage')->name('holidays.store');
    Route::put('/holidays/{holiday}', [HolidayController::class, 'update'])->middleware('can:attendance.manage')->name('holidays.update');
    Route::delete('/holidays/{holiday}', [HolidayController::class, 'destroy'])->middleware('can:attendance.manage')->name('holidays.destroy');

    Route::get('/import', [AttendanceImportController::class, 'index'])->middleware('can:attendance.import')->name('import.index');
    Route::post('/import/preview', [AttendanceImportController::class, 'preview'])->middleware('can:attendance.import')->name('import.preview');
    Route::get('/import/{import}', [AttendanceImportController::class, 'show'])->middleware('can:attendance.import')->name('import.show');
    Route::post('/import/{import}/commit', [AttendanceImportController::class, 'commit'])->middleware('can:attendance.import')->name('import.commit');

    Route::get('/exceptions', [AttendanceExceptionsPageController::class, 'index'])
        ->middleware('can:attendance.view')
        ->name('exceptions.index');

    Route::post('/exceptions/{exception}/resolve', [AttendanceExceptionsPageController::class, 'resolve'])
        ->whereNumber('exception')
        ->middleware('can:attendance.manage')
        ->name('exceptions.resolve');

    Route::post('/exceptions/{exception}/ignore', [AttendanceExceptionsPageController::class, 'ignore'])
        ->whereNumber('exception')
        ->middleware('can:attendance.manage')
        ->name('exceptions.ignore');

    Route::get('/corrections', [AttendanceCorrectionRequestsPageController::class, 'index'])
        ->middleware('can:attendance.corrections.review')
        ->name('corrections.index');

    Route::post('/corrections/{correction}/approve', [AttendanceCorrectionRequestsPageController::class, 'approve'])
        ->whereNumber('correction')
        ->middleware('can:attendance.corrections.review')
        ->name('corrections.approve');

    Route::post('/corrections/{correction}/reject', [AttendanceCorrectionRequestsPageController::class, 'reject'])
        ->whereNumber('correction')
        ->middleware('can:attendance.corrections.review')
        ->name('corrections.reject');

    Route::get('/monthly', [AttendanceMonthlyReportPageController::class, 'index'])
        ->middleware('can:attendance.view')
        ->name('monthly.index');

    Route::get('/records', [AttendanceRecordsPageController::class, 'index'])
        ->middleware('can:attendance.view')
        ->name('index');

    Route::post('/records', [AttendanceRecordsPageController::class, 'store'])
        ->middleware('can:attendance.create')
        ->name('store');

    Route::patch('/records/{record}/checkout', [AttendanceRecordsPageController::class, 'updateCheckout'])
        ->whereNumber('record')
        ->name('records.checkout.update');

    Route::get('/devices', [BiometricDevicesPageController::class, 'index'])
        ->middleware('can:attendance.manage')
        ->name('devices.index');

    Route::post('/devices', [BiometricDevicesPageController::class, 'store'])
        ->middleware('can:attendance.manage')
        ->name('devices.store');

    Route::post('/devices/{device}/ingest', BiometricLogIngestController::class)
        ->whereNumber('device')
        ->middleware('can:attendance.import')
        ->name('devices.ingest');
});
