<?php

use App\Modules\Accounting\Controllers\AccountTransactionController;
use App\Modules\Accounting\Controllers\ExpenseCategoryController;
use App\Modules\Accounting\Controllers\ExpenseController;
use App\Modules\Accounting\Controllers\FinancialAccountController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth:sanctum', 'tenant', 'feature:accounting'])->group(function (): void {
    Route::middleware('company.permission:accounting.view')->group(function (): void {
        Route::get('/accounting/summary', [ExpenseController::class, 'summary']);
        Route::get('/accounting/accounts', [FinancialAccountController::class, 'index']);
        Route::get('/accounting/transactions/export/csv', [AccountTransactionController::class, 'exportCsv']);
        Route::get('/accounting/transactions', [AccountTransactionController::class, 'index']);
        Route::get('/accounting/expense-categories', [ExpenseCategoryController::class, 'index']);
        Route::get('/accounting/expenses/export/csv', [ExpenseController::class, 'exportCsv']);
        Route::get('/accounting/expenses', [ExpenseController::class, 'index']);
    });

    Route::middleware('company.permission:accounting.manage')->group(function (): void {
        Route::post('/accounting/accounts', [FinancialAccountController::class, 'store']);
        Route::patch('/accounting/accounts/{financialAccount}', [FinancialAccountController::class, 'update']);
        Route::post('/accounting/transactions', [AccountTransactionController::class, 'store']);
        Route::post('/accounting/transfers', [AccountTransactionController::class, 'transfer']);
        Route::post('/accounting/expense-categories', [ExpenseCategoryController::class, 'store']);
        Route::patch('/accounting/expense-categories/{expenseCategory}', [ExpenseCategoryController::class, 'update']);
        Route::post('/accounting/expenses', [ExpenseController::class, 'store']);
        Route::patch('/accounting/expenses/{expense}', [ExpenseController::class, 'update']);
    });
});
