<?php

namespace NoahVet\Reef\Infrastructure\Serialization\Jane;

use NoahVet\Reef\Domain\Serialization\Jane\JaneDenormalizerInterface as SelfInterface;
use NoahVet\Reef\Domain\Serialization\Json\JsonSerializerFacadeInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class JaneDenormalizer implements SelfInterface
{
    /**
     * @param list<DenormalizerInterface&NormalizerInterface> $janeObjectNormalizers
     */
    public function __construct(
        protected readonly JsonSerializerFacadeInterface $serializer,
        protected readonly array $janeObjectNormalizers = [],
    ) {
    }

    /**
     * @template T of object
     *
     * @param array<string, mixed> $data
     * @param class-string<T>      $type
     *
     * @return T
     */
    #[\Override]
    public function denormalize(array $data, string $type): object
    {
        /* @var T */
        return $this->serializer->denormalize(
            data: $data,
            type: $type,
            normalizers: $this->janeObjectNormalizers,
        );
    }
}
