<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class SalesAdjustmentRoutes
{
    public static function register(RouteCollectorProxy $g, SalesAdjustmentAction $action, string $uuid): void
    {
        $g->get('/sales/adjustments', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listAdjustments($request)));
        $g->get("/sales/adjustments/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getAdjustment($request, $args['id'])));
        $g->post('/sales/adjustments', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->saveAdjustment($request)));
        $g->put("/sales/adjustments/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->saveAdjustment($request)));
        $g->delete("/sales/adjustments/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteAdjustment($request, $args['id'])));
    }
}
