<?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 AppDocumentTakeBackHydrator implements HydratorInterface
{
    public function __construct(private DocumentManager $dm, private ClassMetadata $class) {}

    public function hydrate(object $document, array $data, array $hints = []): array
    {
        $hydratedData = [];

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

        return $hydratedData;
    }
}