<?php

namespace NoahVet\Reef\Infrastructure\Serialization\Jane;

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

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

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