<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class ContactRoutes
{
    public static function register(RouteCollectorProxy $g, ContactAction $action, string $uuid): void
    {
        $g->get('/contacts', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listContacts($request)));
        $g->get("/contacts/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getContact($request, $args['id'])));
        $g->post('/contacts', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createContact($request)));
        $g->patch("/contacts/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateContact($request, $args['id'])));
        $g->delete("/contacts/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteContact($request, $args['id'])));
    }
}
