<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class AccountingRoutes
{
    public static function register(RouteCollectorProxy $g, AccountingAction $action, string $uuid): void
    {
        $g->get('/accounting/chart', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listChartAccounts($request)));
        $g->post('/accounting/chart', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createChartAccount($request)));
        $g->patch("/accounting/chart/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateChartAccount($request, $args['id'])));

        $g->get('/accounting/journals', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listJournals($request)));
        $g->get("/accounting/journals/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getJournal($request, $args['id'])));
        $g->post('/accounting/journals', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->saveJournal($request)));
        $g->post("/accounting/journals/{id:$uuid}/post", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->postJournal($request, $args['id'])));
    }
}
