<?php

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

Route::middleware('auth')->group(function (): void {
    Route::get('/loan-adjustments',[LoanAdjustmentController::class,'index'])->middleware('permission:loans.adjustments.view')->name('loan-adjustments.index');

    Route::get('/loans/{loan}/early-settlement',[LoanAdjustmentController::class,'settlementForm'])->middleware(['permission:loans.settlement.execute','can:settle,loan'])->name('loan-early-settlements.create');
    Route::post('/loans/{loan}/early-settlement/preview',[LoanAdjustmentController::class,'settlementPreview'])->middleware(['permission:loans.settlement.execute','can:settle,loan'])->name('loan-early-settlements.preview');
    Route::post('/loans/{loan}/early-settlement',[LoanAdjustmentController::class,'settle'])->middleware(['permission:loans.settlement.execute','can:settle,loan'])->name('loan-early-settlements.store');
    Route::get('/loan-early-settlements/{settlement}',[LoanAdjustmentController::class,'settlementShow'])->middleware(['permission:loans.adjustments.view','can:view,settlement'])->name('loan-early-settlements.show');

    Route::get('/loans/{loan}/restructuring',[LoanAdjustmentController::class,'restructuringForm'])->middleware(['permission:loans.restructure.create','can:restructure,loan'])->name('loan-restructurings.create');
    Route::post('/loans/{loan}/restructuring/preview',[LoanAdjustmentController::class,'restructuringPreview'])->middleware(['permission:loans.restructure.create','can:restructure,loan'])->name('loan-restructurings.preview');
    Route::post('/loans/{loan}/restructuring',[LoanAdjustmentController::class,'restructuringStore'])->middleware(['permission:loans.restructure.create','can:restructure,loan'])->name('loan-restructurings.store');
    Route::get('/loan-restructurings/{restructuring}',[LoanAdjustmentController::class,'restructuringShow'])->middleware(['permission:loans.adjustments.view','can:view,restructuring'])->name('loan-restructurings.show');
    Route::post('/loan-restructurings/{restructuring}/decision',[LoanAdjustmentController::class,'restructuringDecision'])->middleware(['permission:loans.restructure.approve','can:decide,restructuring'])->name('loan-restructurings.decision');
    Route::get('/loan-restructurings/{restructuring}/documents/{document}/download',[LoanAdjustmentController::class,'restructuringDocumentDownload'])->middleware(['permission:loans.adjustments.view','can:downloadDocument,restructuring'])->name('loan-restructurings.documents.download');
});
