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

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

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

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

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

            $this->class->propertyAccessors['assignee']->setValue($document, $return);
            $hydratedData['assignee'] = $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['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;
        }

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

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

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

        // EmbedMany
        $mongoData = $data['messages'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\SupportTicket', 'messages', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['messages']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['messages']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['messages']->setValue($document, $return);
        $hydratedData['messages'] = $return;

        // EmbedMany
        $mongoData = $data['actions'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\SupportTicket', 'actions', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['actions']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['actions']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['actions']->setValue($document, $return);
        $hydratedData['actions'] = $return;

        // ReferenceMany
        $mongoData = $data['relatedExpeditions'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\SupportTicket', 'relatedExpeditions', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['relatedExpeditions']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['relatedExpeditions']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['relatedExpeditions']->setValue($document, $return);
        $hydratedData['relatedExpeditions'] = $return;

        // ReferenceMany
        $mongoData = $data['relatedReturnShipments'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\SupportTicket', 'relatedReturnShipments', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['relatedReturnShipments']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['relatedReturnShipments']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['relatedReturnShipments']->setValue($document, $return);
        $hydratedData['relatedReturnShipments'] = $return;

        // ReferenceMany
        $mongoData = $data['relatedSupports'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\SupportTicket', 'relatedSupports', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['relatedSupports']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['relatedSupports']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['relatedSupports']->setValue($document, $return);
        $hydratedData['relatedSupports'] = $return;

        // ReferenceMany
        $mongoData = $data['relatedIncidents'] ?? null;

        if ($mongoData !== null && ! is_array($mongoData)) {
            throw HydratorException::associationTypeMismatch('App\Document\SupportTicket', 'relatedIncidents', 'array', gettype($mongoData));
        }

        $return = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $this->class->fieldMappings['relatedIncidents']);
        $return->setHints($hints);
        $return->setOwner($document, $this->class->fieldMappings['relatedIncidents']);
        $return->setInitialized(false);
        if ($mongoData) {
            $return->setMongoData($mongoData);
        }
        $this->class->propertyAccessors['relatedIncidents']->setValue($document, $return);
        $hydratedData['relatedIncidents'] = $return;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return $hydratedData;
    }
}