<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class PlatformRoutes
{
    public static function register(RouteCollectorProxy $g, PlatformAction $platformAction, string $uuid): void
    {
        $g->get('/platform/users', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $platformAction->listUsers($request)));

        $g->post('/platform/users', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $platformAction->createUser($request)));

        $g->patch("/platform/users/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $platformAction->updateUser($request, $args['id'])));

        $g->get('/platform/audit/events', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $platformAction->listAuditEvents($request)));
    }
}
