<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Services\UserSuggestionService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

final class UserSuggestionsController extends Controller
{
    public function __construct(private readonly UserSuggestionService $suggestions)
    {
    }

    public function __invoke(Request $request): JsonResponse
    {
        $limit = min((int) $request->query('limit', 8), 24);

        return response()->json([
            'data' => $this->suggestions->suggestFor($request->user(), $limit),
        ]);
    }
}
