<?php

declare(strict_types=1);

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

use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\State\ProviderInterface;
use App\Module\Integration\Domain\Service\FileSource;
use App\Module\Integration\Infrastructure\ApiPlatform\Resource\ShareTestConnection;

final readonly class ShareTestConnectionProvider implements ProviderInterface, ProcessorInterface
{
    public function __construct(
        private FileSource $fileSource,
    ) {}

    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ShareTestConnection
    {
        return new ShareTestConnection();
    }

    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ShareTestConnection
    {
        $result = $this->fileSource->test();

        $dto          = new ShareTestConnection();
        $dto->success = $result->success;
        $dto->message = $result->message;

        return $dto;
    }
}
