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

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

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

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

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

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