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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // 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: "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;
    }
}