<?php

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

use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Domain\Manga\Application\Query\GetMangaById;
use App\Domain\Manga\Application\QueryHandler\GetMangaByIdHandler;
use App\Domain\Manga\Infrastructure\ApiPlatform\Dto\MangaDetail;

readonly class GetMangaStateProvider implements ProviderInterface
{
    public function __construct(
        private GetMangaByIdHandler $handler
    ) {
    }

    public function provide(Operation $operation, array $uriVariables = [], array $context = []): MangaDetail
    {
        $query = new GetMangaById($uriVariables['id']);
        $response = $this->handler->handle($query);

        return new MangaDetail(
            id: $response->id,
            title: $response->title,
            slug: $response->slug,
            alternativeSlugs: $response->alternativeSlugs,
            description: $response->description,
            author: $response->author,
            publicationYear: $response->publicationYear,
            genres: $response->genres,
            status: $response->status,
            externalId: $response->externalId,
            imageUrl: $response->imageUrl,
            thumbnailUrl: $response->thumbnailUrl,
            rating: $response->rating,
            monitored: $response->monitored
        );
    }
}
