<?php

namespace App\Download\Action\Input;

use App\Download\Action\Command\DownloadMediaCommand;
use OneToMany\RichBundle\Attribute\SourceRequest;
use OneToMany\RichBundle\Contract\CommandInterface;
use OneToMany\RichBundle\Contract\InputInterface;

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

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

        #[SourceRequest('title')]
        public string $title,

        #[SourceRequest('filename')]
        public string $filename,

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

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

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

        public ?int $userId = null,

        public ?int $downloadId = null,
    ) {}

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