<?php

declare(strict_types=1);

namespace ApiModel\Route;

use ApiModel\Action\BudgetAction;
use ApiModel\Shared\Support\HttpRunner;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Routing\RouteCollectorProxy;

final class BudgetRoutes
{
    public static function register(RouteCollectorProxy $g, BudgetAction $action, string $uuid): void
    {
        // Años Fiscales
        $g->get('/budget/fiscal-years', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listFiscalYears($request)));
        $g->post('/budget/fiscal-years', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createFiscalYear($request)));
        $g->patch("/budget/fiscal-years/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateFiscalYearStatus($request, $args['id'])));

        // Clasificadores
        $g->get('/budget/classifiers', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listClassifiers($request)));
        $g->post('/budget/classifiers', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createClassifier($request)));
        $g->patch("/budget/classifiers/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateClassifier($request, $args['id'])));

        // Unidades Organizacionales
        $g->get('/budget/org-units', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listOrgUnits($request)));
        $g->post('/budget/org-units', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createOrgUnit($request)));
        $g->patch("/budget/org-units/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateOrgUnit($request, $args['id'])));

        // Formulación
        $g->get('/budget/formulations', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listFormulations($request)));
        $g->post('/budget/formulations', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->saveFormulation($request)));

        // Modificaciones
        $g->get('/budget/modifications', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listModifications($request)));
        $g->get("/budget/modifications/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getModification($request, $args['id'])));
        $g->post('/budget/modifications', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createModification($request)));

        // Disponibilidad y Ejecución
        $g->get('/budget/check-availability', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->checkAvailability($request)));
        $g->get('/budget/executions', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listExecutions($request)));
        $g->get('/budget/execution-summary', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->getExecutionSummary($request)));
    }
}
