<?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 Symfony\Component\HttpFoundation\Response;

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

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

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