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

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

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

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

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

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

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

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

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