<?php
declare(strict_types=1);

namespace App\DataProvider\Dolibarr;

use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use App\ApiResources\Dolibarr\DolibarrAccount;
use App\Service\ApiResourceBuilder\Dolibarr\DolibarrAccountBuilder;

/**
 * Custom provider pour les DolibarrAccounts récupérés via l'api dolibarr
 * @package App\DataProvider\Utils
 */
final class DolibarrAccountDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
{

    public function __construct(
        private DolibarrAccountBuilder $dolibarrAccountCreator,
    )
    {}

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

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