<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class ExchangeRateRoutes
{
    public static function register(RouteCollectorProxy $g, ExchangeRateAction $action, string $uuid): void
    {
        $g->get('/accounting/exchange-rates', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listExchangeRates($request)));
        $g->get("/accounting/exchange-rates/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getExchangeRate($request, $args['id'])));
        $g->post('/accounting/exchange-rates', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->saveExchangeRate($request)));
        $g->patch("/accounting/exchange-rates/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->saveExchangeRate($request)));
        $g->delete("/accounting/exchange-rates/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteExchangeRate($request, $args['id'])));
    }
}
