<?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\BookStackTestConnection;
use App\Module\Integration\Infrastructure\Service\BookStackApiService;

final readonly class BookStackTestConnectionProvider implements ProviderInterface, ProcessorInterface
{
    public function __construct(
        private BookStackApiService $bookStackApiService,
    ) {}

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

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

        return $result;
    }
}
