<?php

use Illuminate\Support\Facades\Route;
use Modules\Accounts\Http\Controllers\AccountController;
use Modules\Accounts\Http\Controllers\AccountingPeriodController;
use Modules\Accounts\Http\Controllers\AccountLookupController;
use Modules\Accounts\Http\Controllers\BankAccountController;
use Modules\Accounts\Http\Controllers\VoucherController;

Route::middleware(['api.auth'])->prefix('account-management')->group(function () {
    Route::get('chart-of-accounts/tree', [AccountController::class, 'tree'])->name('chart-of-accounts.tree');
    Route::apiResource('chart-of-accounts', AccountController::class);

    Route::get('vouchers/trial-balance', [VoucherController::class, 'trialBalance'])->name('vouchers.trial-balance');
    Route::get('vouchers/general-ledger', [VoucherController::class, 'generalLedger'])->name('vouchers.general-ledger');
    Route::get('vouchers/account-statement/{account}', [VoucherController::class, 'accountStatement'])->name('vouchers.account-statement');
    Route::post('vouchers/{voucher}/post', [VoucherController::class, 'postVoucher'])->name('vouchers.post');
    Route::post('vouchers/{voucher}/reverse', [VoucherController::class, 'reverseVoucher'])->name('vouchers.reverse');
    Route::apiResource('vouchers', VoucherController::class)->names('vouchers');

    Route::post('bank-accounts/{bankAccount}/deposit', [BankAccountController::class, 'deposit'])->name('bank-accounts.deposit');
    Route::post('bank-accounts/{bankAccount}/withdraw', [BankAccountController::class, 'withdraw'])->name('bank-accounts.withdraw');
    Route::apiResource('bank-accounts', BankAccountController::class)->names('bank-accounts');

    Route::get('account-periods', [AccountingPeriodController::class, 'index']);
});


Route::middleware(['api.auth'])->prefix('accounts/lookups')->group(function () {
    Route::get('account-types', [AccountLookupController::class, 'accountTypes'])->name('accounts.lookups.account-types');
    Route::get('liability-tree', [AccountLookupController::class, 'liabilityTree'])->name('accounts.lookups.liability-tree');
});
