<?php

namespace App\Domain\Setting\Application\CommandHandler;

use App\Domain\Setting\Application\Command\DeleteContentSourceCommand;
use App\Domain\Setting\Domain\Contract\Repository\ContentSourceRepositoryInterface;
use App\Domain\Setting\Domain\Exception\ContentSourceNotFoundException;

readonly class DeleteContentSourceCommandHandler
{
    public function __construct(
        private ContentSourceRepositoryInterface $contentSourceRepository
    ) {
    }

    public function handle(DeleteContentSourceCommand $command): void
    {
        $contentSource = $this->contentSourceRepository->findById($command->id);

        if (!$contentSource) {
            throw new ContentSourceNotFoundException($command->id);
        }

        $this->contentSourceRepository->delete($contentSource);
    }
}
