<?php

declare(strict_types=1);

namespace Apexl\Io\Jobs\Controllers;

use Apexl\Io\Controller;
use Apexl\Io\Jobs\Requests\QueueProcessRequest;
use Apexl\Io\Jobs\Services\TaskRunnerService;
use JsonException;
use Psr\Http\Message\ResponseInterface;

final readonly class QueueProcessController extends Controller
{
    /**
     * @throws JsonException
     */
    public function __invoke(
        TaskRunnerService $taskRunnerService,
        QueueProcessRequest $request,
        ResponseInterface $response,
    ): ResponseInterface {
        $taskRunnerService->run($request->limit());

        return $this->json($response);
    }
}
