<?php

/**
 * RuleTypeSeedPrimitivesDtoAny.
 *
 * PHP version 7.4
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Sync Core.
 *
 * The Sync Core that sends and receives content from all connected sites and services for Content Sync.
 *
 * The version of the OpenAPI document: 1.0
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 6.4.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace EdgeBox\SyncCore\V2\Raw\Model;

use EdgeBox\SyncCore\V2\Raw\ObjectSerializer;

/**
 * RuleTypeSeedPrimitivesDtoAny Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class RuleTypeSeedPrimitivesDtoAny implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     *
     * @var string
     */
    protected static $openAPIModelName = 'RuleTypeSeedPrimitivesDto_Any';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'kind' => 'FormulaTypeKind',
        'nullable' => 'bool',
        'description' => 'string',
        'of' => 'mixed',
        'clarifier' => 'string',
        'properties' => 'mixed',
        'name' => 'string',
        'constraint' => 'FormulaTypeDto',
        'reference' => 'CallableReferenceKind',
        'paramTypes' => '\EdgeBox\SyncCore\V2\Raw\Model\FormulaTypeDto[]',
        'returnType' => 'FormulaTypeDto',
        'minArity' => 'float',
        'maxArity' => 'float',
    ];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static $openAPIFormats = [
        'kind' => null,
        'nullable' => null,
        'description' => null,
        'of' => null,
        'clarifier' => null,
        'properties' => null,
        'name' => null,
        'constraint' => null,
        'reference' => null,
        'paramTypes' => null,
        'returnType' => null,
        'minArity' => null,
        'maxArity' => null,
    ];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'kind' => false,
        'nullable' => true,
        'description' => true,
        'of' => true,
        'clarifier' => true,
        'properties' => true,
        'name' => true,
        'constraint' => true,
        'reference' => true,
        'paramTypes' => true,
        'returnType' => true,
        'minArity' => true,
        'maxArity' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static $attributeMap = [
        'kind' => 'kind',
        'nullable' => 'nullable',
        'description' => 'description',
        'of' => 'of',
        'clarifier' => 'clarifier',
        'properties' => 'properties',
        'name' => 'name',
        'constraint' => 'constraint',
        'reference' => 'reference',
        'paramTypes' => 'paramTypes',
        'returnType' => 'returnType',
        'minArity' => 'minArity',
        'maxArity' => 'maxArity',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static $setters = [
        'kind' => 'setKind',
        'nullable' => 'setNullable',
        'description' => 'setDescription',
        'of' => 'setOf',
        'clarifier' => 'setClarifier',
        'properties' => 'setProperties',
        'name' => 'setName',
        'constraint' => 'setConstraint',
        'reference' => 'setReference',
        'paramTypes' => 'setParamTypes',
        'returnType' => 'setReturnType',
        'minArity' => 'setMinArity',
        'maxArity' => 'setMaxArity',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static $getters = [
        'kind' => 'getKind',
        'nullable' => 'getNullable',
        'description' => 'getDescription',
        'of' => 'getOf',
        'clarifier' => 'getClarifier',
        'properties' => 'getProperties',
        'name' => 'getName',
        'constraint' => 'getConstraint',
        'reference' => 'getReference',
        'paramTypes' => 'getParamTypes',
        'returnType' => 'getReturnType',
        'minArity' => 'getMinArity',
        'maxArity' => 'getMaxArity',
    ];

    /**
     * Associative array for storing property values.
     *
     * @var mixed[]
     */
    protected $container = [];

    /**
     * Constructor.
     *
     * @param mixed[] $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('kind', $data ?? [], null);
        $this->setIfExists('nullable', $data ?? [], null);
        $this->setIfExists('description', $data ?? [], null);
        $this->setIfExists('of', $data ?? [], null);
        $this->setIfExists('clarifier', $data ?? [], null);
        $this->setIfExists('properties', $data ?? [], null);
        $this->setIfExists('name', $data ?? [], null);
        $this->setIfExists('constraint', $data ?? [], null);
        $this->setIfExists('reference', $data ?? [], null);
        $this->setIfExists('paramTypes', $data ?? [], null);
        $this->setIfExists('returnType', $data ?? [], null);
        $this->setIfExists('minArity', $data ?? [], null);
        $this->setIfExists('maxArity', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @return array
     */
    public static function openAPITypes()
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @return array
     */
    public static function openAPIFormats()
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @return array
     */
    public static function attributeMap()
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @return array
     */
    public static function setters()
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @return array
     */
    public static function getters()
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     *
     * @return string
     */
    public function getModelName()
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalidProperties = [];

        if (null === $this->container['kind']) {
            $invalidProperties[] = "'kind' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid()
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets kind.
     *
     * @return FormulaTypeKind
     */
    public function getKind()
    {
        return $this->container['kind'];
    }

    /**
     * Sets kind.
     *
     * @param FormulaTypeKind $kind kind
     *
     * @return self
     */
    public function setKind($kind)
    {
        if (is_null($kind)) {
            throw new \InvalidArgumentException('non-nullable kind cannot be null');
        }
        $this->container['kind'] = $kind;

        return $this;
    }

    /**
     * Gets nullable.
     *
     * @return null|bool
     */
    public function getNullable()
    {
        return $this->container['nullable'];
    }

    /**
     * Sets nullable.
     *
     * @param null|bool $nullable nullable
     *
     * @return self
     */
    public function setNullable($nullable)
    {
        if (is_null($nullable)) {
            array_push($this->openAPINullablesSetToNull, 'nullable');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('nullable', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['nullable'] = $nullable;

        return $this;
    }

    /**
     * Gets description.
     *
     * @return null|string
     */
    public function getDescription()
    {
        return $this->container['description'];
    }

    /**
     * Sets description.
     *
     * @param null|string $description description
     *
     * @return self
     */
    public function setDescription($description)
    {
        if (is_null($description)) {
            array_push($this->openAPINullablesSetToNull, 'description');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('description', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['description'] = $description;

        return $this;
    }

    /**
     * Gets of.
     *
     * @return null|mixed
     */
    public function getOf()
    {
        return $this->container['of'];
    }

    /**
     * Sets of.
     *
     * @param null|mixed $of of
     *
     * @return self
     */
    public function setOf($of)
    {
        if (is_null($of)) {
            array_push($this->openAPINullablesSetToNull, 'of');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('of', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['of'] = $of;

        return $this;
    }

    /**
     * Gets clarifier.
     *
     * @return null|string
     */
    public function getClarifier()
    {
        return $this->container['clarifier'];
    }

    /**
     * Sets clarifier.
     *
     * @param null|string $clarifier clarifier
     *
     * @return self
     */
    public function setClarifier($clarifier)
    {
        if (is_null($clarifier)) {
            array_push($this->openAPINullablesSetToNull, 'clarifier');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('clarifier', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['clarifier'] = $clarifier;

        return $this;
    }

    /**
     * Gets properties.
     *
     * @return null|mixed
     */
    public function getProperties()
    {
        return $this->container['properties'];
    }

    /**
     * Sets properties.
     *
     * @param null|mixed $properties properties
     *
     * @return self
     */
    public function setProperties($properties)
    {
        if (is_null($properties)) {
            array_push($this->openAPINullablesSetToNull, 'properties');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('properties', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['properties'] = $properties;

        return $this;
    }

    /**
     * Gets name.
     *
     * @return null|string
     */
    public function getName()
    {
        return $this->container['name'];
    }

    /**
     * Sets name.
     *
     * @param null|string $name name
     *
     * @return self
     */
    public function setName($name)
    {
        if (is_null($name)) {
            array_push($this->openAPINullablesSetToNull, 'name');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('name', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['name'] = $name;

        return $this;
    }

    /**
     * Gets constraint.
     *
     * @return null|FormulaTypeDto
     */
    public function getConstraint()
    {
        return $this->container['constraint'];
    }

    /**
     * Sets constraint.
     *
     * @param null|FormulaTypeDto $constraint constraint
     *
     * @return self
     */
    public function setConstraint($constraint)
    {
        if (is_null($constraint)) {
            array_push($this->openAPINullablesSetToNull, 'constraint');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('constraint', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['constraint'] = $constraint;

        return $this;
    }

    /**
     * Gets reference.
     *
     * @return null|CallableReferenceKind
     */
    public function getReference()
    {
        return $this->container['reference'];
    }

    /**
     * Sets reference.
     *
     * @param null|CallableReferenceKind $reference reference
     *
     * @return self
     */
    public function setReference($reference)
    {
        if (is_null($reference)) {
            array_push($this->openAPINullablesSetToNull, 'reference');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('reference', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['reference'] = $reference;

        return $this;
    }

    /**
     * Gets paramTypes.
     *
     * @return null|FormulaTypeDto[]
     */
    public function getParamTypes()
    {
        return $this->container['paramTypes'];
    }

    /**
     * Sets paramTypes.
     *
     * @param null|FormulaTypeDto[] $paramTypes paramTypes
     *
     * @return self
     */
    public function setParamTypes($paramTypes)
    {
        if (is_null($paramTypes)) {
            array_push($this->openAPINullablesSetToNull, 'paramTypes');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('paramTypes', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['paramTypes'] = $paramTypes;

        return $this;
    }

    /**
     * Gets returnType.
     *
     * @return null|FormulaTypeDto
     */
    public function getReturnType()
    {
        return $this->container['returnType'];
    }

    /**
     * Sets returnType.
     *
     * @param null|FormulaTypeDto $returnType returnType
     *
     * @return self
     */
    public function setReturnType($returnType)
    {
        if (is_null($returnType)) {
            array_push($this->openAPINullablesSetToNull, 'returnType');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('returnType', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['returnType'] = $returnType;

        return $this;
    }

    /**
     * Gets minArity.
     *
     * @return null|float
     */
    public function getMinArity()
    {
        return $this->container['minArity'];
    }

    /**
     * Sets minArity.
     *
     * @param null|float $minArity minArity
     *
     * @return self
     */
    public function setMinArity($minArity)
    {
        if (is_null($minArity)) {
            array_push($this->openAPINullablesSetToNull, 'minArity');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('minArity', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['minArity'] = $minArity;

        return $this;
    }

    /**
     * Gets maxArity.
     *
     * @return null|float
     */
    public function getMaxArity()
    {
        return $this->container['maxArity'];
    }

    /**
     * Sets maxArity.
     *
     * @param null|float $maxArity maxArity
     *
     * @return self
     */
    public function setMaxArity($maxArity)
    {
        if (is_null($maxArity)) {
            array_push($this->openAPINullablesSetToNull, 'maxArity');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('maxArity', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['maxArity'] = $maxArity;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset)
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     * of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize()
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     *
     * @return string
     */
    public function toHeaderValue()
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed  $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
