<?php

declare(strict_types=1);

namespace ApiModel\Route;

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

final class InventoryRoutes
{
    public static function register(RouteCollectorProxy $g, InventoryAction $action, string $uuid): void
    {
        // Categories
        $g->get('/inventory/categories', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listCategories($request)));
        $g->get("/inventory/categories/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getCategory($request, $args['id'])));
        $g->post('/inventory/categories', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->saveCategory($request)));
        $g->patch("/inventory/categories/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->saveCategory($request, $args['id'])));
        $g->delete("/inventory/categories/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteCategory($request, $args['id'])));

        // Items (Products & Services)
        $g->get('/inventory/items', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listItems($request)));
        $g->get("/inventory/items/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getItem($request, $args['id'])));
        $g->post('/inventory/items', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->saveItem($request)));
        $g->patch("/inventory/items/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->saveItem($request, $args['id'])));
        $g->delete("/inventory/items/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteItem($request, $args['id'])));

        // Warehouses
        $g->get('/inventory/warehouses', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listWarehouses($request)));
        $g->get("/inventory/warehouses/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getWarehouse($request, $args['id'])));
        $g->post('/inventory/warehouses', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->saveWarehouse($request)));
        $g->patch("/inventory/warehouses/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->saveWarehouse($request, $args['id'])));
        $g->delete("/inventory/warehouses/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteWarehouse($request, $args['id'])));
        $g->get("/inventory/warehouses/{id:$uuid}/stock", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getWarehouseStock($request, $args['id'])));

        // Adjustments
        $g->get('/inventory/adjustments', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listAdjustments($request)));
        $g->get("/inventory/adjustments/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getAdjustment($request, $args['id'])));
        $g->post('/inventory/adjustments', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->saveAdjustment($request)));
        $g->patch("/inventory/adjustments/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->saveAdjustment($request, $args['id'])));
        $g->delete("/inventory/adjustments/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteAdjustment($request, $args['id'])));

        // Transfers
        $g->get('/inventory/transfers', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->listTransfers($request)));
        $g->get("/inventory/transfers/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->getTransfer($request, $args['id'])));
        $g->post('/inventory/transfers', fn (ServerRequestInterface $request, ResponseInterface $response) => HttpRunner::runJson($request, $response, fn () => $action->saveTransfer($request)));
        $g->patch("/inventory/transfers/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->saveTransfer($request, $args['id'])));
        $g->delete("/inventory/transfers/{id:$uuid}", fn (ServerRequestInterface $request, ResponseInterface $response, array $args) => HttpRunner::runJson($request, $response, fn () => $action->deleteTransfer($request, $args['id'])));
    }
}
