<?php

declare(strict_types=1);

namespace App\Domain\Reader\Infrastructure\ApiPlatform\State\Provider;

use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Domain\Reader\Application\Query\GetChapterPage;
use App\Domain\Reader\Application\QueryHandler\GetChapterPageHandler;
use App\Domain\Reader\Application\Response\ChapterPageResponse;

final readonly class ChapterPageProvider implements ProviderInterface
{
    public function __construct(
        private GetChapterPageHandler $handler
    ) {
    }

    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ChapterPageResponse
    {
        return $this->handler->handle(
            new GetChapterPage(
                $uriVariables['chapterId'],
                (int) $uriVariables['pageNumber']
            )
        );
    }
} 