<?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\Infrastructure\ApiPlatform\Resource\GiteaTestConnection;
use App\Module\Integration\Infrastructure\Service\GiteaApiService;

final readonly class GiteaTestConnectionProvider implements ProviderInterface, ProcessorInterface
{
    public function __construct(
        private GiteaApiService $giteaApiService,
    ) {}

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

    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): GiteaTestConnection
    {
        $result          = new GiteaTestConnection();
        $result->success = $this->giteaApiService->testConnection();

        return $result;
    }
}
