<?php

namespace App\Search\Action\Handler;

use App\Search\Action\Command\GetMediaInfoCommand;
use App\Search\Action\Result\GetMediaInfoResult;
use App\Tmdb\Tmdb;
use OneToMany\RichBundle\Contract\CommandInterface;
use OneToMany\RichBundle\Contract\HandlerInterface;
use OneToMany\RichBundle\Contract\ResultInterface;

/** @implements HandlerInterface<GetMediaInfoCommand, GetMediaInfoResult> */
class GetMediaInfoHandler implements HandlerInterface
{
    public function __construct(
        private readonly Tmdb $tmdb,
    ) {}

    public function handle(CommandInterface $command): ResultInterface
    {
        $media = $this->tmdb->mediaDetails($command->imdbId, $command->mediaType);

        return new GetMediaInfoResult($media, $command->season);
    }
}
