<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class FerreteriaRoutes
{
    public static function register(RouteCollectorProxy $g, FerreteriaAction $action, string $uuid): void
    {
        $g->get('/ferreterias', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listar($request)));
        $g->get("/ferreterias/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->obtener($request, $args['id'])));
        $g->post('/ferreterias', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->crear($request)));
        $g->patch("/ferreterias/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->actualizar($request, $args['id'])));
    }
}
