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

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

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

        return $hydratedData;
    }
}