<?php

use App\Http\Controllers\ArrearsController;
use App\Http\Controllers\LoanInstallmentExcuseController;
use Illuminate\Support\Facades\Route;

Route::middleware('auth')->group(function (): void {
    Route::get('/arrears', [ArrearsController::class, 'index'])
        ->middleware('permission:arrears.view')
        ->name('arrears.index');
    Route::get('/arrears/{loan}', [ArrearsController::class, 'show'])
        ->middleware(['permission:arrears.view', 'can:viewArrears,loan'])
        ->name('arrears.show');
    Route::post('/arrears/{loan}/follow-ups', [ArrearsController::class, 'storeFollowUp'])
        ->middleware(['permission:arrears.follow-up', 'can:followUpArrears,loan'])
        ->name('arrears.follow-ups.store');

    Route::post('/loans/{loan}/installments/{installment}/excuse', [LoanInstallmentExcuseController::class, 'store'])
        ->middleware(['permission:loans.installments.excuse', 'can:excuseInstallment,loan'])
        ->name('loans.installments.excuse.store');
    Route::delete('/loans/{loan}/installments/{installment}/excuse', [LoanInstallmentExcuseController::class, 'destroy'])
        ->middleware(['permission:loans.installments.excuse', 'can:excuseInstallment,loan'])
        ->name('loans.installments.excuse.destroy');
});
