<?php

declare(strict_types=1);

namespace App\DataProvider\Cotisation;

use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use App\ApiResources\Cotisation\Cotisation;
use App\Service\Cotisation\CotisationCreator;

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

    public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
    {
        return Cotisation::class === $resourceClass;
    }

    public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?Cotisation
    {
        return $this->cotisationCreator->getCotisation($id);
    }
}