<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class CurrencyRoutes
{
    public static function register(RouteCollectorProxy $g, CurrencyAction $action, string $uuid): void
    {
        $g->get('/currencies', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listCurrencies($request)));
        $g->get("/currencies/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getCurrency($request, $args['id'])));
        $g->post('/currencies', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createCurrency($request)));
        $g->patch("/currencies/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateCurrency($request, $args['id'])));
        $g->delete("/currencies/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteCurrency($request, $args['id'])));
    }
}
