<?php
declare(strict_types=1);

namespace Controllers;

use Helpers\Response;
use Services\CategoryService;
use Services\ProductService;

final class CategoryController
{
    public function index(): never { Response::success((new CategoryService())->list()); }
    public function products(string $slug): never
    {
        $category = (new CategoryService())->find($slug);
        if (!$category) Response::error('Category not found', 404);
        $products = (new ProductService())->list(['category' => $slug] + $_GET);
        Response::success(['category' => $category, 'products' => $products]);
    }
}
