<?php

/**
 * OperatorDefinitionDto.
 *
 * 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;

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

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

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'token' => 'string',
        'precedence' => 'float',
        'associativity' => 'string',
        'functionSignatureId' => 'string',
        'inputTypes' => '\EdgeBox\SyncCore\V2\Raw\Model\FormulaTypeDto[]',
        'outputType' => 'FormulaTypeDto',
        'implicitCastsAllowed' => 'bool',
    ];

    /**
     * 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 = [
        'token' => null,
        'precedence' => null,
        'associativity' => null,
        'functionSignatureId' => null,
        'inputTypes' => null,
        'outputType' => null,
        'implicitCastsAllowed' => null,
    ];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'token' => false,
        'precedence' => false,
        'associativity' => false,
        'functionSignatureId' => false,
        'inputTypes' => true,
        'outputType' => true,
        'implicitCastsAllowed' => 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 = [
        'token' => 'token',
        'precedence' => 'precedence',
        'associativity' => 'associativity',
        'functionSignatureId' => 'functionSignatureId',
        'inputTypes' => 'inputTypes',
        'outputType' => 'outputType',
        'implicitCastsAllowed' => 'implicitCastsAllowed',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static $setters = [
        'token' => 'setToken',
        'precedence' => 'setPrecedence',
        'associativity' => 'setAssociativity',
        'functionSignatureId' => 'setFunctionSignatureId',
        'inputTypes' => 'setInputTypes',
        'outputType' => 'setOutputType',
        'implicitCastsAllowed' => 'setImplicitCastsAllowed',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static $getters = [
        'token' => 'getToken',
        'precedence' => 'getPrecedence',
        'associativity' => 'getAssociativity',
        'functionSignatureId' => 'getFunctionSignatureId',
        'inputTypes' => 'getInputTypes',
        'outputType' => 'getOutputType',
        'implicitCastsAllowed' => 'getImplicitCastsAllowed',
    ];

    /**
     * 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('token', $data ?? [], null);
        $this->setIfExists('precedence', $data ?? [], null);
        $this->setIfExists('associativity', $data ?? [], null);
        $this->setIfExists('functionSignatureId', $data ?? [], null);
        $this->setIfExists('inputTypes', $data ?? [], null);
        $this->setIfExists('outputType', $data ?? [], null);
        $this->setIfExists('implicitCastsAllowed', $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['token']) {
            $invalidProperties[] = "'token' can't be null";
        }
        if (null === $this->container['precedence']) {
            $invalidProperties[] = "'precedence' can't be null";
        }
        if (null === $this->container['associativity']) {
            $invalidProperties[] = "'associativity' can't be null";
        }
        if (null === $this->container['functionSignatureId']) {
            $invalidProperties[] = "'functionSignatureId' 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 token.
     *
     * @return string
     */
    public function getToken()
    {
        return $this->container['token'];
    }

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

        return $this;
    }

    /**
     * Gets precedence.
     *
     * @return float
     */
    public function getPrecedence()
    {
        return $this->container['precedence'];
    }

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

        return $this;
    }

    /**
     * Gets associativity.
     *
     * @return string
     */
    public function getAssociativity()
    {
        return $this->container['associativity'];
    }

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

        return $this;
    }

    /**
     * Gets functionSignatureId.
     *
     * @return string
     */
    public function getFunctionSignatureId()
    {
        return $this->container['functionSignatureId'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        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;
    }
}
