<?php

use App\Http\Controllers\LoanWriteOffController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth','module:loan_writeoffs'])->group(function (): void {
    Route::get('/loan-write-offs',[LoanWriteOffController::class,'index'])
        ->middleware('permission:loans.writeoff.view')->name('loan-write-offs.index');

    Route::get('/loans/{loan}/write-off',[LoanWriteOffController::class,'create'])
        ->middleware(['permission:loans.writeoff.request','can:requestWriteOff,loan'])->name('loan-write-offs.create');
    Route::post('/loans/{loan}/write-off',[LoanWriteOffController::class,'store'])
        ->middleware(['permission:loans.writeoff.request','can:requestWriteOff,loan'])->name('loan-write-offs.store');

    Route::get('/loan-write-offs/{writeOff}',[LoanWriteOffController::class,'show'])
        ->middleware(['permission:loans.writeoff.view','can:view,writeOff'])->name('loan-write-offs.show');
    Route::post('/loan-write-offs/{writeOff}/decision',[LoanWriteOffController::class,'decision'])
        ->middleware(['permission:loans.writeoff.approve','can:decide,writeOff'])->name('loan-write-offs.decision');
    Route::get('/loan-write-offs/{writeOff}/documents/{document}/download',[LoanWriteOffController::class,'documentDownload'])
        ->middleware(['permission:loans.writeoff.view','can:downloadDocument,writeOff'])->name('loan-write-offs.documents.download');

    Route::get('/loan-write-offs/{writeOff}/recoveries/create',[LoanWriteOffController::class,'recoveryForm'])
        ->middleware(['permission:loans.writeoff.recover','can:recover,writeOff'])->name('loan-write-offs.recoveries.create');
    Route::post('/loan-write-offs/{writeOff}/recoveries',[LoanWriteOffController::class,'recover'])
        ->middleware(['permission:loans.writeoff.recover','can:recover,writeOff'])->name('loan-write-offs.recoveries.store');
});
