<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class TaxRateRoutes
{
    public static function register(RouteCollectorProxy $g, TaxRateAction $action, string $uuid): void
    {
        $g->get('/taxes', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listTaxRates($request)));
        $g->get("/taxes/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getTaxRate($request, $args['id'])));
        $g->post('/taxes', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createTaxRate($request)));
        $g->patch("/taxes/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateTaxRate($request, $args['id'])));
        $g->delete("/taxes/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteTaxRate($request, $args['id'])));
    }
}
