<?php

namespace Myvetshop\Module\Clinique\Generated\Jane\Normalizer;

use Myvetshop\Module\Clinique\Generated\Jane\Runtime\Normalizer\CheckArray;
use Myvetshop\Module\Clinique\Generated\Jane\Runtime\Normalizer\ValidatorTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class JaneObjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
{
    use DenormalizerAwareTrait;
    use NormalizerAwareTrait;
    use CheckArray;
    use ValidatorTrait;
    protected $normalizers = ['Myvetshop\\Module\\Clinique\\Generated\\Jane\\Model\\ClinicsGetResponse200Item' => 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Normalizer\\ClinicsGetResponse200ItemNormalizer', 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Model\\OrdersGetResponse200Item' => 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Normalizer\\OrdersGetResponse200ItemNormalizer', 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Model\\OrdersGetResponse200ItemProductsItem' => 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Normalizer\\OrdersGetResponse200ItemProductsItemNormalizer', 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Model\\OrdersGetResponse200ItemDiscountsItem' => 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Normalizer\\OrdersGetResponse200ItemDiscountsItemNormalizer', 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Model\\OrdersGetResponse200ItemRefundsItem' => 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Normalizer\\OrdersGetResponse200ItemRefundsItemNormalizer', 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Model\\ProductCategoriesGetResponse200Item' => 'Myvetshop\\Module\\Clinique\\Generated\\Jane\\Normalizer\\ProductCategoriesGetResponse200ItemNormalizer', '\\Jane\\Component\\JsonSchemaRuntime\\Reference' => '\\Myvetshop\\Module\\Clinique\\Generated\\Jane\\Runtime\\Normalizer\\ReferenceNormalizer'];
    protected $normalizersCache = [];

    public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
    {
        return array_key_exists($type, $this->normalizers);
    }

    public function supportsNormalization($data, $format = null, array $context = []): bool
    {
        return is_object($data) && array_key_exists(get_class($data), $this->normalizers);
    }

    /**
     * @return array|string|int|float|bool|\ArrayObject|null
     */
    public function normalize($object, $format = null, array $context = [])
    {
        $normalizerClass = $this->normalizers[get_class($object)];
        $normalizer = $this->getNormalizer($normalizerClass);

        return $normalizer->normalize($object, $format, $context);
    }

    /**
     * @return mixed
     */
    public function denormalize($data, $class, $format = null, array $context = [])
    {
        $denormalizerClass = $this->normalizers[$class];
        $denormalizer = $this->getNormalizer($denormalizerClass);

        return $denormalizer->denormalize($data, $class, $format, $context);
    }

    private function getNormalizer(string $normalizerClass)
    {
        return $this->normalizersCache[$normalizerClass] ?? $this->initNormalizer($normalizerClass);
    }

    private function initNormalizer(string $normalizerClass)
    {
        $normalizer = new $normalizerClass();
        $normalizer->setNormalizer($this->normalizer);
        $normalizer->setDenormalizer($this->denormalizer);
        $this->normalizersCache[$normalizerClass] = $normalizer;

        return $normalizer;
    }
}
