<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class OrganizationRoutes
{
    public static function register(RouteCollectorProxy $g, OrganizationAction $action, string $uuid): void
    {
        $g->get('/organization/my-context', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->getMyContext($request)));

        $g->get('/organization/companies', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listCompanies($request)));
        $g->post('/organization/companies', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createCompany($request)));
        $g->patch("/organization/companies/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateCompany($request, $args['id'])));

        $g->get("/organization/companies/{companyId:$uuid}/branches", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->listBranches($request, $args['companyId'])));
        $g->post("/organization/companies/{companyId:$uuid}/branches", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->createBranch($request, $args['companyId'])));
        $g->patch("/organization/branches/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateBranch($request, $args['id'])));
        $g->delete("/organization/branches/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteBranch($request, $args['id'])));


        $g->get("/organization/users/{userId:$uuid}/access", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getUserAccess($request, $args['userId'])));
        $g->put("/organization/users/{userId:$uuid}/access", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->setUserAccess($request, $args['userId'])));
    }
}
