<?php
use App\Domains\CostUnit\Controllers\ChangeStateController;
use App\Domains\CostUnit\Controllers\CreateController;
use App\Domains\CostUnit\Controllers\DistanceAllowanceController;
use App\Domains\CostUnit\Controllers\EditController;
use App\Domains\CostUnit\Controllers\ExportController;
use App\Domains\CostUnit\Controllers\GlobalSepaExportController;
use App\Domains\CostUnit\Controllers\ListController;
use App\Domains\CostUnit\Controllers\OpenController;
use App\Domains\CostUnit\Controllers\TreasurersEditController;
use App\Middleware\IdentifyTenant;
use Illuminate\Support\Facades\Route;

Route::prefix('api/v1')
    ->group(function () {
        Route::middleware(IdentifyTenant::class)->group(function () {
            Route::prefix('cost-unit')->group(function () {

                Route::get('/get-distance-allowance/{costUnitId}',  DistanceAllowanceController::class);


                Route::middleware(['auth'])->group(function () {
                    Route::post('/create-running-job', [CreateController::class, 'createCostUnitRunningJob']);


                    Route::prefix('/{costUnitId}') ->group(function () {
                        Route::get('/invoice-list/{invoiceStatus}', [OpenController::class, 'listInvoices']);




                        Route::post('/close', [ChangeStateController::class, 'close']);
                        Route::post('/open', [ChangeStateController::class, 'open']);
                        Route::post('/archive', [ChangeStateController::class, 'archive']);

                        Route::get('/details', EditController::class);
                        Route::post('/details', [EditController::class, 'update']);

                        Route::get('/treasurers', TreasurersEditController::class);
                        Route::post('/treasurers', [TreasurersEditController::class, 'update']);

                        Route::get('/export-payouts', ExportController::class);
                    });



                    Route::get('/global-actions', [GlobalSepaExportController::class, 'getGlobalActions']);
                    Route::get('/export-sepa-file', [GlobalSepaExportController::class, 'exportSepaFile']);

                    Route::prefix('open')->group(function () {
                        Route::get('/current-events', [ListController::class, 'listCurrentEvents']);
                        Route::get('/current-running-jobs', [ListController::class, 'listCurrentRunningJobs']);
                        Route::get('/closed-cost-units', [ListController::class, 'listClosedCostUnits']);
                        Route::get('/archived-cost-units', [ListController::class, 'listArchivedCostUnits']);
                    });
                });
            });
        });
    });
