<?php

namespace Symfony\Config\ElaoEnum;

require_once __DIR__.\DIRECTORY_SEPARATOR.'DoctrineMongodb'.\DIRECTORY_SEPARATOR.'TypeConfig.php';

use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

/**
 * This class is automatically generated to help in creating a config.
 */
class DoctrineMongodbConfig 
{
    private $types;
    private $_usedProperties = [];

    /**
     * @template TValue of string|array
     * @param TValue $value
     * @return \Symfony\Config\ElaoEnum\DoctrineMongodb\TypeConfig|$this
     * @psalm-return (TValue is array ? \Symfony\Config\ElaoEnum\DoctrineMongodb\TypeConfig : static)
     */
    public function type(string $name, string|array $value = []): \Symfony\Config\ElaoEnum\DoctrineMongodb\TypeConfig|static
    {
        if (!\is_array($value)) {
            $this->_usedProperties['types'] = true;
            $this->types[$name] = $value;

            return $this;
        }

        if (!isset($this->types[$name]) || !$this->types[$name] instanceof \Symfony\Config\ElaoEnum\DoctrineMongodb\TypeConfig) {
            $this->_usedProperties['types'] = true;
            $this->types[$name] = new \Symfony\Config\ElaoEnum\DoctrineMongodb\TypeConfig($value);
        } elseif (1 < \func_num_args()) {
            throw new InvalidConfigurationException('The node created by "type()" has already been initialized. You cannot pass values the second time you call type().');
        }

        return $this->types[$name];
    }

    public function __construct(array $config = [])
    {
        if (array_key_exists('types', $config)) {
            $this->_usedProperties['types'] = true;
            $this->types = array_map(fn ($v) => \is_array($v) ? new \Symfony\Config\ElaoEnum\DoctrineMongodb\TypeConfig($v) : $v, $config['types']);
            unset($config['types']);
        }

        if ($config) {
            throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($config)));
        }
    }

    public function toArray(): array
    {
        $output = [];
        if (isset($this->_usedProperties['types'])) {
            $output['types'] = array_map(fn ($v) => $v instanceof \Symfony\Config\ElaoEnum\DoctrineMongodb\TypeConfig ? $v->toArray() : $v, $this->types);
        }

        return $output;
    }

}
