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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // Field(type: "countryCollection")
        if (isset($data['forbiddenCountries']) || (! empty($this->class->fieldMappings['forbiddenCountries']['nullable']) && array_key_exists('forbiddenCountries', $data))) {
            $value = $data['forbiddenCountries'];
            if ($value !== null) {
                $typeIdentifier = $this->class->fieldMappings['forbiddenCountries']['type'];
                
            $type = \Doctrine\ODM\MongoDB\Types\Type::getType($typeIdentifier);
            $return = $type->convertToPHPValue($value);
            } else {
                $return = null;
            }
            $this->class->propertyAccessors['forbiddenCountries']->setValue($document, $return);
            $hydratedData['forbiddenCountries'] = $return;
        }

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

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

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

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

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