<?php

namespace App\Http\Controllers;

use App\Services\CategoryDirectoryService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
    public function __construct(
        private readonly CategoryDirectoryService $directory,
    ) {}

    public function index(Request $request): JsonResponse
    {
        return response()->json($this->directory->getDirectoryPayload(
            (string) $request->query('q', ''),
            (string) $request->query('sort', 'popular'),
            (int) $request->query('page', 1),
            (int) $request->query('per_page', 24),
        ));
    }
}
