<?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 AppDocumentDepositHydrator implements HydratorInterface
{
    public function __construct(private DocumentManager $dm, private ClassMetadata $class) {}

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

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

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

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

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

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

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

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

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

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

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

        // EmbedOne
        if (isset($data['coordinates']) || (! empty($this->class->fieldMappings['coordinates']['nullable']) && array_key_exists('coordinates', $data))) {
            $return = $data['coordinates'];
            if ($return !== null) {
                $embeddedDocument = $return;

                if (! is_array($embeddedDocument)) {
                    throw HydratorException::associationTypeMismatch('App\Document\Deposit', 'coordinates', 'array', gettype($embeddedDocument));
                }
        
                $className = $this->dm->getClassNameForAssociation($this->class->fieldMappings['coordinates'], $embeddedDocument);
                $embeddedMetadata = $this->dm->getClassMetadata($className);
                $return = $embeddedMetadata->newInstance();

                $this->dm->getUnitOfWork()->setParentAssociation($return, $this->class->fieldMappings['coordinates'], $document, 'coordinates');

                $embeddedData = $this->dm->getHydratorFactory()->hydrate($return, $embeddedDocument, $hints);
                $embeddedId = $embeddedMetadata->identifier && isset($embeddedData[$embeddedMetadata->identifier]) ? $embeddedData[$embeddedMetadata->identifier] : null;

                if (empty($hints[Query::HINT_READ_ONLY])) {
                    $this->dm->getUnitOfWork()->registerManaged($return, $embeddedId, $embeddedData);
                }
            }

            $this->class->propertyAccessors['coordinates']->setValue($document, $return);
            $hydratedData['coordinates'] = $return;
        }

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

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

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

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

        // Field(type: "date")
        if (array_key_exists('createdAt', $data) && ($data['createdAt'] !== null || ($this->class->fieldMappings['createdAt']['nullable'] ?? false))) {
            $value = $data['createdAt'];
            if ($value === null) { $return = null; } else { $return = \Doctrine\ODM\MongoDB\Types\DateType::getDateTime($value); }
            $this->class->propertyAccessors['createdAt']->setValue($document, $return === null ? null : clone $return);
            $hydratedData['createdAt'] = $return;
        }

        // Field(type: "date")
        if (array_key_exists('updatedAt', $data) && ($data['updatedAt'] !== null || ($this->class->fieldMappings['updatedAt']['nullable'] ?? false))) {
            $value = $data['updatedAt'];
            if ($value === null) { $return = null; } else { $return = \Doctrine\ODM\MongoDB\Types\DateType::getDateTime($value); }
            $this->class->propertyAccessors['updatedAt']->setValue($document, $return === null ? null : clone $return);
            $hydratedData['updatedAt'] = $return;
        }

        return $hydratedData;
    }
}