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

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

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

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

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