<?php

namespace App\Download\Action\Handler;

use App\Download\Action\Command\DeleteDownloadCommand;
use App\Download\Action\Result\DeleteDownloadResult;
use App\Download\Framework\Repository\DownloadRepository;
use OneToMany\RichBundle\Contract\CommandInterface;
use OneToMany\RichBundle\Contract\HandlerInterface;
use OneToMany\RichBundle\Contract\ResultInterface;

/** @implements HandlerInterface<DeleteDownloadCommand, DeleteDownloadResult> */
readonly class DeleteDownloadHandler implements HandlerInterface
{
    public function __construct(
        private DownloadRepository $downloadRepository,
    ) {}

    public function handle(CommandInterface $command): ResultInterface
    {
        $download = $this->downloadRepository->find($command->downloadId);
        $this->downloadRepository->delete($command->downloadId);

        return new DeleteDownloadResult(200, 'Success', $download);
    }
}
