<?php

namespace App\Torrentio\Action\Handler;

use App\Base\Service\MediaFiles;
use App\Tmdb\TmdbClient;
use App\Torrentio\Action\Result\GetMovieOptionsResult;
use App\Torrentio\Client\Torrentio;
use OneToMany\RichBundle\Contract\CommandInterface;
use OneToMany\RichBundle\Contract\HandlerInterface;
use OneToMany\RichBundle\Contract\ResultInterface;

class GetMovieOptionsHandler implements HandlerInterface
{
    public function __construct(
        private readonly TmdbClient $tmdb,
        private readonly Torrentio $torrentio,
        private readonly MediaFiles $mediaFiles
    ) {}

    public function handle(CommandInterface $command): ResultInterface
    {
        $media = $this->tmdb->movieDetails($command->imdbId);
        return new GetMovieOptionsResult(
            media: $media,
            file: $this->mediaFiles->movieExists($media->title),
            results: $this->torrentio->search($command->imdbId, 'movies'),
        );
    }
}
