<?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 RuntimeException;

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

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

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