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

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

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

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

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

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

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

        return $hydratedData;
    }
}