<?php

namespace App\Download\Action\Input;

use App\Download\Action\Command\DownloadMediaCommand;
use OneToMany\RichBundle\Attribute\PropertyIgnored;
use OneToMany\RichBundle\Attribute\SourceRequest;
use OneToMany\RichBundle\Attribute\SourceRoute;
use OneToMany\RichBundle\Attribute\SourceSecurity;
use OneToMany\RichBundle\Contract\CommandInterface;
use OneToMany\RichBundle\Contract\InputInterface;
use Symfony\Component\Security\Core\User\UserInterface;

/** @implements InputInterface<DownloadMediaInput> */
class DownloadMediaInput implements InputInterface
{
    public ?string $mercureAlertTopic = null;

    public function __construct(
        #[SourceRequest('imdbId')]
        #[SourceRoute('imdbId')]
        public string $imdbId,

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

        #[SourceRequest('season')]
        #[SourceRoute('season')]
        public int|string|null $season = null,

        #[SourceRequest('episode')]
        #[SourceRoute('episode')]
        public int|string|null $episode = null,

        #[SourceRequest('url', nullify: true)]
        public string|null $url = null,

        #[SourceRequest('filter', nullify: true)]
        public array|null $filter = null,

        #[PropertyIgnored]
        public int|null $downloadId = null,

        #[PropertyIgnored]
        public int|null $userId = null,
    ) {}

    public function setUserId(int $userId): static
    {
        $this->userId = $userId;
        return $this;
    }

    public function setDownloadId(int $downloadId): static
    {
        $this->downloadId = $downloadId;
        return $this;
    }

    public function setMercureAlertTopic(string $mercureAlertTopic): static
    {
        $this->mercureAlertTopic = $mercureAlertTopic;
        return $this;
    }

    public function toCommand(): CommandInterface
    {
        return new DownloadMediaCommand(
            $this->imdbId,
            $this->mediaType,
            (int) $this->season,
            (int) $this->episode,
            $this->url,
            $this->filter,
            $this->downloadId,
            $this->userId,
            $this->mercureAlertTopic,
        );
    }
}