<?php

namespace Hydrators;

use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Hydrator\HydratorException;
use Doctrine\ODM\MongoDB\Hydrator\HydratorInterface;
use Doctrine\ODM\MongoDB\Query\Query;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;

use function array_key_exists;
use function gettype;
use function is_array;

/**
 * THIS CLASS WAS GENERATED BY THE DOCTRINE ODM. DO NOT EDIT THIS FILE.
 */
class AppDocumentCustomsAddressHydrator implements HydratorInterface
{
    public function __construct(private DocumentManager $dm, private ClassMetadata $class) {}

    public function hydrate(object $document, array $data, array $hints = []): array
    {
        $hydratedData = [];

        // Field(type: "string")
        if (isset($data['companyName']) || (! empty($this->class->fieldMappings['companyName']['nullable']) && array_key_exists('companyName', $data))) {
            $value = $data['companyName'];
            if ($value !== null) {
                $typeIdentifier = $this->class->fieldMappings['companyName']['type'];
                $return = (string) $value;
            } else {
                $return = null;
            }
            $this->class->propertyAccessors['companyName']->setValue($document, $return);
            $hydratedData['companyName'] = $return;
        }

        // Field(type: "string")
        if (isset($data['street']) || (! empty($this->class->fieldMappings['street']['nullable']) && array_key_exists('street', $data))) {
            $value = $data['street'];
            if ($value !== null) {
                $typeIdentifier = $this->class->fieldMappings['street']['type'];
                $return = (string) $value;
            } else {
                $return = null;
            }
            $this->class->propertyAccessors['street']->setValue($document, $return);
            $hydratedData['street'] = $return;
        }

        // Field(type: "string")
        if (isset($data['houseNumber']) || (! empty($this->class->fieldMappings['houseNumber']['nullable']) && array_key_exists('houseNumber', $data))) {
            $value = $data['houseNumber'];
            if ($value !== null) {
                $typeIdentifier = $this->class->fieldMappings['houseNumber']['type'];
                $return = (string) $value;
            } else {
                $return = null;
            }
            $this->class->propertyAccessors['houseNumber']->setValue($document, $return);
            $hydratedData['houseNumber'] = $return;
        }

        // Field(type: "string")
        if (isset($data['zipcode']) || (! empty($this->class->fieldMappings['zipcode']['nullable']) && array_key_exists('zipcode', $data))) {
            $value = $data['zipcode'];
            if ($value !== null) {
                $typeIdentifier = $this->class->fieldMappings['zipcode']['type'];
                $return = (string) $value;
            } else {
                $return = null;
            }
            $this->class->propertyAccessors['zipcode']->setValue($document, $return);
            $hydratedData['zipcode'] = $return;
        }

        // Field(type: "string")
        if (isset($data['city']) || (! empty($this->class->fieldMappings['city']['nullable']) && array_key_exists('city', $data))) {
            $value = $data['city'];
            if ($value !== null) {
                $typeIdentifier = $this->class->fieldMappings['city']['type'];
                $return = (string) $value;
            } else {
                $return = null;
            }
            $this->class->propertyAccessors['city']->setValue($document, $return);
            $hydratedData['city'] = $return;
        }

        // Field(type: "string")
        if (isset($data['country']) || (! empty($this->class->fieldMappings['country']['nullable']) && array_key_exists('country', $data))) {
            $value = $data['country'];
            if ($value !== null) {
                $typeIdentifier = $this->class->fieldMappings['country']['type'];
                $return = (string) $value;
            } else {
                $return = null;
            }
            $this->class->propertyAccessors['country']->setValue($document, $return);
            $hydratedData['country'] = $return;
        }

        return $hydratedData;
    }
}