<?php

declare(strict_types=1);

namespace App\Module\Integration\Infrastructure\ApiPlatform\State;

use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Module\Integration\Domain\Repository\GiteaConfigurationRepositoryInterface;
use App\Module\Integration\Infrastructure\ApiPlatform\Resource\GiteaSettings;

final readonly class GiteaSettingsProvider implements ProviderInterface
{
    public function __construct(
        private GiteaConfigurationRepositoryInterface $configRepository,
    ) {}

    public function provide(Operation $operation, array $uriVariables = [], array $context = []): GiteaSettings
    {
        $config = $this->configRepository->findSingleton();
        $dto    = new GiteaSettings();

        if (null !== $config) {
            $dto->url      = $config->getUrl();
            $dto->hasToken = $config->hasToken();
        }

        return $dto;
    }
}
