<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class HrRoutes
{
    public static function register(RouteCollectorProxy $g, HrAction $action, string $uuid): void
    {
        // Departments
        $g->get('/hr/departments', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listDepartments($request)));
        $g->get("/hr/departments/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getDepartment($request, $args['id'])));
        $g->post('/hr/departments', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createDepartment($request)));
        $g->put("/hr/departments/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateDepartment($request, $args['id'])));
        $g->delete("/hr/departments/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteDepartment($request, $args['id'])));

        // Employees
        $g->get('/hr/employees', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listEmployees($request)));
        $g->get("/hr/employees/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getEmployee($request, $args['id'])));
        $g->post('/hr/employees', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createEmployee($request)));
        $g->put("/hr/employees/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateEmployee($request, $args['id'])));
        $g->delete("/hr/employees/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteEmployee($request, $args['id'])));

        // Payrolls
        $g->get('/hr/payrolls', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listPayrolls($request)));
        $g->get("/hr/payrolls/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getPayroll($request, $args['id'])));
        $g->post('/hr/payrolls', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createPayroll($request)));
        $g->put("/hr/payrolls/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updatePayroll($request, $args['id'])));
        $g->delete("/hr/payrolls/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deletePayroll($request, $args['id'])));
        $g->post("/hr/payrolls/{id:$uuid}/post", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->postPayroll($request, $args['id'])));

        // Leaves
        $g->get('/hr/leaves', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listLeaves($request)));
        $g->get("/hr/leaves/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getLeave($request, $args['id'])));
        $g->post('/hr/leaves', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->createLeave($request)));
        $g->put("/hr/leaves/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->updateLeave($request, $args['id'])));
        $g->delete("/hr/leaves/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteLeave($request, $args['id'])));
    }
}
