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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // EmbedMany
        $mongoData = $data['takeBacks'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'takeBacks', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['takeBacks']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['takeBacks']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['takeBacks']->setValue($document, $return);
        $hydratedData['takeBacks'] = $return;

        // EmbedMany
        $mongoData = $data['expeditionLines'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'expeditionLines', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['expeditionLines']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['expeditionLines']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['expeditionLines']->setValue($document, $return);
        $hydratedData['expeditionLines'] = $return;

        // EmbedMany
        $mongoData = $data['transferHistoryLines'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'transferHistoryLines', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['transferHistoryLines']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['transferHistoryLines']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['transferHistoryLines']->setValue($document, $return);
        $hydratedData['transferHistoryLines'] = $return;

        // ReferenceMany
        $mongoData = $data['supports'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'supports', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['supports']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['supports']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['supports']->setValue($document, $return);
        $hydratedData['supports'] = $return;

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

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

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

                $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['deliveryAddress']->setValue($document, $return);
            $hydratedData['deliveryAddress'] = $return;
        }

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

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

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

                $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['deliverySlot']->setValue($document, $return);
            $hydratedData['deliverySlot'] = $return;
        }

        // ReferenceOne
        if (isset($data['everestMission']) || (! empty($this->class->fieldMappings['everestMission']['nullable']) && array_key_exists('everestMission', $data))) {
            $return = $data['everestMission'];
            if ($return !== null) {
                if ($this->class->fieldMappings['everestMission']['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID && ! is_array($return)) {
                    throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'everestMission', 'array', gettype($return));
                }

                $className = $this->dm->getClassNameForAssociation($this->class->fieldMappings['everestMission'], $return);
                $identifier = ClassMetadata::getReferenceId($return, $this->class->fieldMappings['everestMission']['storeAs']);
                $targetMetadata = $this->dm->getClassMetadata($className);
                $id = $targetMetadata->getPHPIdentifierValue($identifier);
                $return = $this->dm->getReference($className, $id);
            }

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

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

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

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

                $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['trackingInfos']->setValue($document, $return);
            $hydratedData['trackingInfos'] = $return;
        }

        // ReferenceMany
        $mongoData = $data['followUps'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'followUps', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['followUps']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['followUps']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['followUps']->setValue($document, $return);
        $hydratedData['followUps'] = $return;

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

        // ReferenceOne
        if (isset($data['orderGiver']) || (! empty($this->class->fieldMappings['orderGiver']['nullable']) && array_key_exists('orderGiver', $data))) {
            $return = $data['orderGiver'];
            if ($return !== null) {
                if ($this->class->fieldMappings['orderGiver']['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID && ! is_array($return)) {
                    throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'orderGiver', 'array', gettype($return));
                }

                $className = $this->dm->getClassNameForAssociation($this->class->fieldMappings['orderGiver'], $return);
                $identifier = ClassMetadata::getReferenceId($return, $this->class->fieldMappings['orderGiver']['storeAs']);
                $targetMetadata = $this->dm->getClassMetadata($className);
                $id = $targetMetadata->getPHPIdentifierValue($identifier);
                $return = $this->dm->getReference($className, $id);
            }

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

        // ReferenceOne
        if (isset($data['organization']) || (! empty($this->class->fieldMappings['organization']['nullable']) && array_key_exists('organization', $data))) {
            $return = $data['organization'];
            if ($return !== null) {
                if ($this->class->fieldMappings['organization']['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID && ! is_array($return)) {
                    throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'organization', 'array', gettype($return));
                }

                $className = $this->dm->getClassNameForAssociation($this->class->fieldMappings['organization'], $return);
                $identifier = ClassMetadata::getReferenceId($return, $this->class->fieldMappings['organization']['storeAs']);
                $targetMetadata = $this->dm->getClassMetadata($className);
                $id = $targetMetadata->getPHPIdentifierValue($identifier);
                $return = $this->dm->getReference($className, $id);
            }

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

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

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

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

        // ReferenceOne
        if (isset($data['deposit']) || (! empty($this->class->fieldMappings['deposit']['nullable']) && array_key_exists('deposit', $data))) {
            $return = $data['deposit'];
            if ($return !== null) {
                if ($this->class->fieldMappings['deposit']['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID && ! is_array($return)) {
                    throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'deposit', 'array', gettype($return));
                }

                $className = $this->dm->getClassNameForAssociation($this->class->fieldMappings['deposit'], $return);
                $identifier = ClassMetadata::getReferenceId($return, $this->class->fieldMappings['deposit']['storeAs']);
                $targetMetadata = $this->dm->getClassMetadata($className);
                $id = $targetMetadata->getPHPIdentifierValue($identifier);
                $return = $this->dm->getReference($className, $id);
            }

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

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

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

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

                $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['relayPoint']->setValue($document, $return);
            $hydratedData['relayPoint'] = $return;
        }

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

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

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

                $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['logisticsDetails']->setValue($document, $return);
            $hydratedData['logisticsDetails'] = $return;
        }

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

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

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

        $mapping = $this->class->fieldMappings['returnShipment'];
        $className = $mapping['targetDocument'];
        $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
        $mappedByMapping = $targetClass->fieldMappings[$mapping['mappedBy']];
        $mappedByFieldName = ClassMetadata::getReferenceFieldName($mappedByMapping['storeAs'], $mapping['mappedBy']);
        $criteria = array_merge(
            [$mappedByFieldName => $data['_id']],
            $this->class->fieldMappings['returnShipment']['criteria'] ?? []
        );
        $sort = $this->class->fieldMappings['returnShipment']['sort'] ?? [];
        $return = $this->dm->getUnitOfWork()->getDocumentPersister($className)->load($criteria, null, [], 0, $sort);
        $this->class->propertyAccessors['returnShipment']->setValue($document, $return);
        $hydratedData['returnShipment'] = $return;

        $mapping = $this->class->fieldMappings['relatedReturnShipment'];
        $className = $mapping['targetDocument'];
        $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
        $mappedByMapping = $targetClass->fieldMappings[$mapping['mappedBy']];
        $mappedByFieldName = ClassMetadata::getReferenceFieldName($mappedByMapping['storeAs'], $mapping['mappedBy']);
        $criteria = array_merge(
            [$mappedByFieldName => $data['_id']],
            $this->class->fieldMappings['relatedReturnShipment']['criteria'] ?? []
        );
        $sort = $this->class->fieldMappings['relatedReturnShipment']['sort'] ?? [];
        $return = $this->dm->getUnitOfWork()->getDocumentPersister($className)->load($criteria, null, [], 0, $sort);
        $this->class->propertyAccessors['relatedReturnShipment']->setValue($document, $return);
        $hydratedData['relatedReturnShipment'] = $return;

        // ReferenceOne
        if (isset($data['marketplace']) || (! empty($this->class->fieldMappings['marketplace']['nullable']) && array_key_exists('marketplace', $data))) {
            $return = $data['marketplace'];
            if ($return !== null) {
                if ($this->class->fieldMappings['marketplace']['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID && ! is_array($return)) {
                    throw HydratorException::associationTypeMismatch('App\Document\Expedition', 'marketplace', 'array', gettype($return));
                }

                $className = $this->dm->getClassNameForAssociation($this->class->fieldMappings['marketplace'], $return);
                $identifier = ClassMetadata::getReferenceId($return, $this->class->fieldMappings['marketplace']['storeAs']);
                $targetMetadata = $this->dm->getClassMetadata($className);
                $id = $targetMetadata->getPHPIdentifierValue($identifier);
                $return = $this->dm->getReference($className, $id);
            }

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

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

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

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

                $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['firstAvailableSlot']->setValue($document, $return);
            $hydratedData['firstAvailableSlot'] = $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;
    }
}