<?php

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

Route::prefix('hr/attendance')->name('hr.attendance.')->middleware('module:hr')->group(function () {
    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('/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');
});
