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

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

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

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

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

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

        return $hydratedData;
    }
}