<?php

namespace NoahVet\Reef\Infrastructure\Serialization\Jane;

use NoahVet\Reef\Domain\Serialization\Jane\JaneDenormalizerInterface;
use NoahVet\Reef\Domain\Serialization\Jane\JaneDeserializerInterface;
use NoahVet\Reef\Domain\Serialization\Jane\JaneNormalizerInterface;
use NoahVet\Reef\Domain\Serialization\Jane\JaneSerializerFacadeInterface as SelfInterface;

class JaneSerializerFacade implements SelfInterface
{
    public function __construct(
        protected readonly JaneDeserializerInterface $janeDeserializer,
        protected readonly JaneDenormalizerInterface $janeDenormalizer,
        protected readonly JaneNormalizerInterface $janeNormalizer,
    ) {
    }

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

    /**
     * @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
    {
        return $this->janeDenormalizer->denormalize(data: $data, type: $type);
    }

    /**
     * @return array<string, mixed>
     */
    #[\Override]
    public function normalize(object $object): array
    {
        return $this->janeNormalizer->normalize(object: $object);
    }
}
