<?php

declare(strict_types=1);

namespace App\State\Provider\Cotisation;

use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\ApiResources\Cotisation\Cotisation;
use App\Service\Cotisation\CotisationCreator;
use Symfony\Component\HttpFoundation\Response;

/**
 * Class CotisationProvider : custom provider pour assurer l'alimentation de la réponse du GET cotisation.
 */
final class CotisationProvider implements ProviderInterface
{
    public function __construct(private CotisationCreator $cotisationCreator)
    {
    }

    /**
     * @param mixed[] $uriVariables
     * @param mixed[] $context
     */
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): Cotisation
    {
        if ($operation instanceof GetCollection) {
            throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);
        }

        return $this->cotisationCreator->getCotisation($uriVariables['organizationId']);
    }
}
