<?php

use App\Modules\HR\Loans\Controllers\LoanController;
use App\Modules\HR\Loans\Models\Loan;
use Illuminate\Support\Facades\Route;

Route::prefix('hr/loans')->name('hr.loans.')->middleware('module:hr')->group(function (): void {
    Route::get('/', [LoanController::class, 'index'])->middleware('can:loans.view')->name('index');
    Route::get('/create', [LoanController::class, 'create'])->middleware('can:loans.create')->name('create');
    Route::post('/', [LoanController::class, 'store'])->middleware('can:loans.create')->name('store');
    Route::get('/{loan}', [LoanController::class, 'show'])->middleware('can:view,loan')->name('show');
    Route::get('/{loan}/edit', [LoanController::class, 'edit'])->middleware('can:update,loan')->name('edit');
    Route::put('/{loan}', [LoanController::class, 'update'])->middleware('can:update,loan')->name('update');
    Route::delete('/{loan}', [LoanController::class, 'destroy'])->middleware('can:manage,loan')->name('destroy');
    foreach (['submit', 'approve', 'reject', 'cancel', 'settle'] as $action) {
        Route::post('/{loan}/'.$action, fn (LoanController $controller, Loan $loan) => $controller->action($loan, $action))
            ->name($action);
    }
});
