<?php
declare(strict_types=1);

namespace App\State\Provider\Mobyt;

use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\ApiResources\Mobyt\MobytUserStatus;
use App\Service\ApiResourceBuilder\Mobyt\MobytUserStatusBuilder;
use JsonException;
use RuntimeException;

/**
 * Custom provider pour les MobytUserStatus récupérés via l'api Mobyt
 * @package App\DataProvider\Utils
 */
final class MobytUserStatusProvider implements ProviderInterface
{
    public function __construct(
        private MobytUserStatusBuilder $mobytUserStatusCreator,
    )
    {}

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

        return $this->mobytUserStatusCreator->getUserStatus((int) $uriVariables['id']);
    }
}
