<?php

namespace NoahVet\Reef\Jane\Normalizer;

use Jane\Component\JsonSchemaRuntime\Reference;
use NoahVet\Reef\Jane\Runtime\Normalizer\CheckArray;
use NoahVet\Reef\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 SchemasVeterinaryEstablishmentRequestNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
{
    use CheckArray;
    use DenormalizerAwareTrait;
    use NormalizerAwareTrait;
    use ValidatorTrait;

    public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
    {
        return \NoahVet\Reef\Jane\Model\SchemasVeterinaryEstablishmentRequest::class === $type;
    }

    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
    {
        return \is_object($data) && \NoahVet\Reef\Jane\Model\SchemasVeterinaryEstablishmentRequest::class === $data::class;
    }

    public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
    {
        if (isset($data['$ref'])) {
            return new Reference($data['$ref'], $context['document-origin']);
        }
        if (isset($data['$recursiveRef'])) {
            return new Reference($data['$recursiveRef'], $context['document-origin']);
        }
        $object = new \NoahVet\Reef\Jane\Model\SchemasVeterinaryEstablishmentRequest();
        if (null === $data || false === \is_array($data)) {
            return $object;
        }
        if (\array_key_exists('banner', $data) && null !== $data['banner']) {
            $object->setBanner($this->denormalizer->denormalize($data['banner'], \NoahVet\Reef\Jane\Model\NullableIdRequest::class, 'json', $context));
            unset($data['banner']);
        } elseif (\array_key_exists('banner', $data) && null === $data['banner']) {
            $object->setBanner(null);
        }
        if (\array_key_exists('customName', $data) && null !== $data['customName']) {
            $object->setCustomName($data['customName']);
            unset($data['customName']);
        } elseif (\array_key_exists('customName', $data) && null === $data['customName']) {
            $object->setCustomName(null);
        }
        if (\array_key_exists('entryNumber', $data) && null !== $data['entryNumber']) {
            $object->setEntryNumber($data['entryNumber']);
            unset($data['entryNumber']);
        } elseif (\array_key_exists('entryNumber', $data) && null === $data['entryNumber']) {
            $object->setEntryNumber(null);
        }
        if (\array_key_exists('internalCommentary', $data) && null !== $data['internalCommentary']) {
            $object->setInternalCommentary($data['internalCommentary']);
            unset($data['internalCommentary']);
        } elseif (\array_key_exists('internalCommentary', $data) && null === $data['internalCommentary']) {
            $object->setInternalCommentary(null);
        }
        if (\array_key_exists('legalStructure', $data) && null !== $data['legalStructure']) {
            $object->setLegalStructure($this->denormalizer->denormalize($data['legalStructure'], \NoahVet\Reef\Jane\Model\NullableIdRequest::class, 'json', $context));
            unset($data['legalStructure']);
        } elseif (\array_key_exists('legalStructure', $data) && null === $data['legalStructure']) {
            $object->setLegalStructure(null);
        }
        if (\array_key_exists('logo', $data) && null !== $data['logo']) {
            $object->setLogo($this->denormalizer->denormalize($data['logo'], \NoahVet\Reef\Jane\Model\NullableIdRequest::class, 'json', $context));
            unset($data['logo']);
        } elseif (\array_key_exists('logo', $data) && null === $data['logo']) {
            $object->setLogo(null);
        }
        if (\array_key_exists('longDescription', $data) && null !== $data['longDescription']) {
            $object->setLongDescription($data['longDescription']);
            unset($data['longDescription']);
        } elseif (\array_key_exists('longDescription', $data) && null === $data['longDescription']) {
            $object->setLongDescription(null);
        }
        if (\array_key_exists('mainAddress', $data) && null !== $data['mainAddress']) {
            $object->setMainAddress($this->denormalizer->denormalize($data['mainAddress'], \NoahVet\Reef\Jane\Model\NullableIdRequest::class, 'json', $context));
            unset($data['mainAddress']);
        } elseif (\array_key_exists('mainAddress', $data) && null === $data['mainAddress']) {
            $object->setMainAddress(null);
        }
        if (\array_key_exists('mainBillingAccount', $data) && null !== $data['mainBillingAccount']) {
            $object->setMainBillingAccount($this->denormalizer->denormalize($data['mainBillingAccount'], \NoahVet\Reef\Jane\Model\NullableIdRequest::class, 'json', $context));
            unset($data['mainBillingAccount']);
        } elseif (\array_key_exists('mainBillingAccount', $data) && null === $data['mainBillingAccount']) {
            $object->setMainBillingAccount(null);
        }
        if (\array_key_exists('name', $data) && null !== $data['name']) {
            $object->setName($data['name']);
            unset($data['name']);
        } elseif (\array_key_exists('name', $data) && null === $data['name']) {
            $object->setName(null);
        }
        if (\array_key_exists('personalisedMention', $data) && null !== $data['personalisedMention']) {
            $object->setPersonalisedMention($data['personalisedMention']);
            unset($data['personalisedMention']);
        } elseif (\array_key_exists('personalisedMention', $data) && null === $data['personalisedMention']) {
            $object->setPersonalisedMention(null);
        }
        if (\array_key_exists('pictures', $data) && null !== $data['pictures']) {
            $values = [];
            foreach ($data['pictures'] as $value) {
                $values[] = $this->denormalizer->denormalize($value, \NoahVet\Reef\Jane\Model\IdRequest::class, 'json', $context);
            }
            $object->setPictures($values);
            unset($data['pictures']);
        } elseif (\array_key_exists('pictures', $data) && null === $data['pictures']) {
            $object->setPictures(null);
        }
        if (\array_key_exists('schedule', $data) && null !== $data['schedule']) {
            $object->setSchedule($this->denormalizer->denormalize($data['schedule'], \NoahVet\Reef\Jane\Model\SchemasVeterinaryEstablishmentRequestSchedule::class, 'json', $context));
            unset($data['schedule']);
        } elseif (\array_key_exists('schedule', $data) && null === $data['schedule']) {
            $object->setSchedule(null);
        }
        if (\array_key_exists('serviceVatCategory', $data) && null !== $data['serviceVatCategory']) {
            $object->setServiceVatCategory($data['serviceVatCategory']);
            unset($data['serviceVatCategory']);
        } elseif (\array_key_exists('serviceVatCategory', $data) && null === $data['serviceVatCategory']) {
            $object->setServiceVatCategory(null);
        }
        if (\array_key_exists('shortDescription', $data) && null !== $data['shortDescription']) {
            $object->setShortDescription($data['shortDescription']);
            unset($data['shortDescription']);
        } elseif (\array_key_exists('shortDescription', $data) && null === $data['shortDescription']) {
            $object->setShortDescription(null);
        }
        if (\array_key_exists('type', $data) && null !== $data['type']) {
            $object->setType($data['type']);
            unset($data['type']);
        } elseif (\array_key_exists('type', $data) && null === $data['type']) {
            $object->setType(null);
        }
        foreach ($data as $key => $value_1) {
            if (\preg_match('/.*/', (string) $key)) {
                $object[$key] = $value_1;
            }
        }

        return $object;
    }

    public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
    {
        $dataArray = [];
        if ($data->isInitialized('banner') && null !== $data->getBanner()) {
            $dataArray['banner'] = $this->normalizer->normalize($data->getBanner(), 'json', $context);
        }
        if ($data->isInitialized('customName') && null !== $data->getCustomName()) {
            $dataArray['customName'] = $data->getCustomName();
        }
        if ($data->isInitialized('entryNumber') && null !== $data->getEntryNumber()) {
            $dataArray['entryNumber'] = $data->getEntryNumber();
        }
        if ($data->isInitialized('internalCommentary') && null !== $data->getInternalCommentary()) {
            $dataArray['internalCommentary'] = $data->getInternalCommentary();
        }
        if ($data->isInitialized('legalStructure') && null !== $data->getLegalStructure()) {
            $dataArray['legalStructure'] = $this->normalizer->normalize($data->getLegalStructure(), 'json', $context);
        }
        if ($data->isInitialized('logo') && null !== $data->getLogo()) {
            $dataArray['logo'] = $this->normalizer->normalize($data->getLogo(), 'json', $context);
        }
        if ($data->isInitialized('longDescription') && null !== $data->getLongDescription()) {
            $dataArray['longDescription'] = $data->getLongDescription();
        }
        if ($data->isInitialized('mainAddress') && null !== $data->getMainAddress()) {
            $dataArray['mainAddress'] = $this->normalizer->normalize($data->getMainAddress(), 'json', $context);
        }
        if ($data->isInitialized('mainBillingAccount') && null !== $data->getMainBillingAccount()) {
            $dataArray['mainBillingAccount'] = $this->normalizer->normalize($data->getMainBillingAccount(), 'json', $context);
        }
        if ($data->isInitialized('name') && null !== $data->getName()) {
            $dataArray['name'] = $data->getName();
        }
        if ($data->isInitialized('personalisedMention') && null !== $data->getPersonalisedMention()) {
            $dataArray['personalisedMention'] = $data->getPersonalisedMention();
        }
        if ($data->isInitialized('pictures') && null !== $data->getPictures()) {
            $values = [];
            foreach ($data->getPictures() as $value) {
                $values[] = $this->normalizer->normalize($value, 'json', $context);
            }
            $dataArray['pictures'] = $values;
        }
        if ($data->isInitialized('schedule') && null !== $data->getSchedule()) {
            $dataArray['schedule'] = $this->normalizer->normalize($data->getSchedule(), 'json', $context);
        }
        if ($data->isInitialized('serviceVatCategory') && null !== $data->getServiceVatCategory()) {
            $dataArray['serviceVatCategory'] = $data->getServiceVatCategory();
        }
        if ($data->isInitialized('shortDescription') && null !== $data->getShortDescription()) {
            $dataArray['shortDescription'] = $data->getShortDescription();
        }
        if ($data->isInitialized('type') && null !== $data->getType()) {
            $dataArray['type'] = $data->getType();
        }
        foreach ($data as $key => $value_1) {
            if (\preg_match('/.*/', (string) $key)) {
                $dataArray[$key] = $value_1;
            }
        }

        return $dataArray;
    }

    public function getSupportedTypes(?string $format = null): array
    {
        return [\NoahVet\Reef\Jane\Model\SchemasVeterinaryEstablishmentRequest::class => false];
    }
}
