<?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\ShareConfigurationRepositoryInterface;
use App\Module\Integration\Infrastructure\ApiPlatform\Resource\ShareSettings;

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

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

        if (null !== $config) {
            $dto->host        = $config->getHost();
            $dto->shareName   = $config->getShareName();
            $dto->basePath    = $config->getBasePath();
            $dto->domain      = $config->getDomain();
            $dto->username    = $config->getUsername();
            $dto->enabled     = $config->isEnabled();
            $dto->hasPassword = $config->hasPassword();
        }

        return $dto;
    }
}
