<?php

namespace App\Domain\Setting\Application\QueryHandler;

use App\Domain\Setting\Application\Query\GetContentSourceQuery;
use App\Domain\Setting\Application\Response\ContentSourceResponse;
use App\Domain\Setting\Domain\Contract\Repository\ContentSourceRepositoryInterface;
use App\Domain\Setting\Domain\Exception\ContentSourceNotFoundException;

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

    public function handle(GetContentSourceQuery $query): ContentSourceResponse
    {
        $contentSource = $this->contentSourceRepository->findById($query->id);

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

        return ContentSourceResponse::fromDomain($contentSource);
    }
}
