<?php

namespace App\Search\Action\Input;

use App\Search\Action\Command\GetMediaInfoCommand;
use OneToMany\RichBundle\Attribute\SourceRoute;
use OneToMany\RichBundle\Contract\CommandInterface;
use OneToMany\RichBundle\Contract\InputInterface;

/** @implements InputInterface<GetMediaInfoInput> */
class GetMediaInfoInput implements InputInterface
{
    public function __construct(
        #[SourceRoute('imdbId')]
        public string $imdbId,

        #[SourceRoute('mediaType')]
        public string $mediaType,

        #[SourceRoute('season', nullify: true)]
        public ?int $season,

        #[SourceRoute('episode', nullify: true)]
        public ?int $episode,
    ) {}

    public function toCommand(): CommandInterface
    {
        if ("tvshows" === $this->mediaType  && null === $this->season) {
            $this->season = 1;
        }

        if ("tvshows" === $this->mediaType && null === $this->episode) {
            $this->episode = 1;
        }
        return new GetMediaInfoCommand($this->imdbId, $this->mediaType, $this->season, $this->episode);
    }
}