<?php

use App\Http\Controllers\CreditScoreCalibrationReportController;
use App\Http\Controllers\CreditScorePortfolioReportController;
use App\Http\Controllers\FinancialReportController;
use App\Http\Controllers\LoanBranchReportController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth', 'module:financial_reports'])->group(function (): void {
    Route::get('/reports/{report}/export.csv', [FinancialReportController::class, 'export'])
        ->where('report', 'trial-balance|income-statement|statement-of-financial-position|portfolio-summary|profit-loss|cash-flow|account-statement|capital|expenses|payroll|collections|disbursements')
        ->middleware('permission:reports.export')
        ->name('reports.export');
    Route::get('/reports/{report?}', [FinancialReportController::class, 'index'])
        ->where('report', 'trial-balance|income-statement|statement-of-financial-position|portfolio-summary|profit-loss|cash-flow|account-statement|capital|expenses|payroll|collections|disbursements')
        ->middleware('permission:reports.view')
        ->name('reports.index');

    Route::get('/loan-branch-reports/{report}/export.csv', [LoanBranchReportController::class, 'export'])
        ->where('report', 'active-loan-portfolio|outstanding-principal|outstanding-interest|due-today|overdue-loans|completed-loans|written-off-loans|loan-collection-rate|branch-performance|company-performance|loan-officer-performance|collateral-report|top-up-report|restructuring-report|write-off-recovery-report')
        ->middleware('permission:reports.export')
        ->name('loan-branch-reports.export');
    Route::get('/loan-branch-reports/{report?}', [LoanBranchReportController::class, 'index'])
        ->where('report', 'active-loan-portfolio|outstanding-principal|outstanding-interest|due-today|overdue-loans|completed-loans|written-off-loans|loan-collection-rate|branch-performance|company-performance|loan-officer-performance|collateral-report|top-up-report|restructuring-report|write-off-recovery-report')
        ->middleware('permission:reports.view')
        ->name('loan-branch-reports.index');

    Route::get('/credit-score-reports/portfolio/export.csv', [CreditScorePortfolioReportController::class, 'export'])
        ->middleware('permission:reports.export')
        ->name('credit-score-reports.export');
    Route::get('/credit-score-reports/portfolio', [CreditScorePortfolioReportController::class, 'index'])
        ->middleware('permission:reports.view')
        ->name('credit-score-reports.portfolio');

    Route::get('/credit-score-reports/calibration/export.csv', [CreditScoreCalibrationReportController::class, 'export'])
        ->middleware('permission:reports.export')
        ->name('credit-score-reports.calibration.export');
    Route::get('/credit-score-reports/calibration', [CreditScoreCalibrationReportController::class, 'index'])
        ->middleware('permission:reports.view')
        ->name('credit-score-reports.calibration');
});
