<?php

declare(strict_types=1);

namespace App\State;

use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\ApiResource\ShareSettings;
use App\Repository\ShareConfigurationRepository;

final readonly class ShareSettingsProvider implements ProviderInterface
{
    public function __construct(
        private ShareConfigurationRepository $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;
    }
}
