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

        // ReferenceOne
        if (isset($data['author']) || (! empty($this->class->fieldMappings['author']['nullable']) && array_key_exists('author', $data))) {
            $return = $data['author'];
            if ($return !== null) {
                if ($this->class->fieldMappings['author']['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID && ! is_array($return)) {
                    throw HydratorException::associationTypeMismatch('App\Document\SupportTicketMessage', 'author', 'array', gettype($return));
                }

                $className = $this->dm->getClassNameForAssociation($this->class->fieldMappings['author'], $return);
                $identifier = ClassMetadata::getReferenceId($return, $this->class->fieldMappings['author']['storeAs']);
                $targetMetadata = $this->dm->getClassMetadata($className);
                $id = $targetMetadata->getPHPIdentifierValue($identifier);
                $return = $this->dm->getReference($className, $id);
            }

            $this->class->propertyAccessors['author']->setValue($document, $return);
            $hydratedData['author'] = $return;
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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