<?php

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

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

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

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'ok' => 'bool',
        'returnType' => 'string',
        'static' => 'bool',
        'predictableValue' => 'mixed',
        'requirements' => '\EdgeBox\SyncCore\V2\Raw\Model\ParseFormulaResponseRequirements',
        'errors' => '\EdgeBox\SyncCore\V2\Raw\Model\FormulaErrorDto[]',
        'ast' => '\EdgeBox\SyncCore\V2\Raw\Model\ParseFormulaResponseAst',
        'formula' => 'string',
    ];

    /**
     * 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 = [
        'ok' => null,
        'returnType' => null,
        'static' => null,
        'predictableValue' => null,
        'requirements' => null,
        'errors' => null,
        'ast' => null,
        'formula' => null,
    ];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'ok' => false,
        'returnType' => false,
        'static' => false,
        'predictableValue' => true,
        'requirements' => false,
        'errors' => false,
        'ast' => false,
        'formula' => false,
    ];

    /**
     * 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 = [
        'ok' => 'ok',
        'returnType' => 'returnType',
        'static' => 'static',
        'predictableValue' => 'predictableValue',
        'requirements' => 'requirements',
        'errors' => 'errors',
        'ast' => 'ast',
        'formula' => 'formula',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static $setters = [
        'ok' => 'setOk',
        'returnType' => 'setReturnType',
        'static' => 'setStatic',
        'predictableValue' => 'setPredictableValue',
        'requirements' => 'setRequirements',
        'errors' => 'setErrors',
        'ast' => 'setAst',
        'formula' => 'setFormula',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static $getters = [
        'ok' => 'getOk',
        'returnType' => 'getReturnType',
        'static' => 'getStatic',
        'predictableValue' => 'getPredictableValue',
        'requirements' => 'getRequirements',
        'errors' => 'getErrors',
        'ast' => 'getAst',
        'formula' => 'getFormula',
    ];

    /**
     * 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('ok', $data ?? [], null);
        $this->setIfExists('returnType', $data ?? [], null);
        $this->setIfExists('static', $data ?? [], null);
        $this->setIfExists('predictableValue', $data ?? [], null);
        $this->setIfExists('requirements', $data ?? [], null);
        $this->setIfExists('errors', $data ?? [], null);
        $this->setIfExists('ast', $data ?? [], null);
        $this->setIfExists('formula', $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['ok']) {
            $invalidProperties[] = "'ok' can't be null";
        }
        if (null === $this->container['returnType']) {
            $invalidProperties[] = "'returnType' can't be null";
        }
        if (null === $this->container['static']) {
            $invalidProperties[] = "'static' can't be null";
        }
        if (null === $this->container['requirements']) {
            $invalidProperties[] = "'requirements' can't be null";
        }
        if (null === $this->container['errors']) {
            $invalidProperties[] = "'errors' can't be null";
        }
        if (null === $this->container['ast']) {
            $invalidProperties[] = "'ast' can't be null";
        }
        if (null === $this->container['formula']) {
            $invalidProperties[] = "'formula' 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 ok.
     *
     * @return bool
     */
    public function getOk()
    {
        return $this->container['ok'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets static.
     *
     * @return bool
     */
    public function getStatic()
    {
        return $this->container['static'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets requirements.
     *
     * @return ParseFormulaResponseRequirements
     */
    public function getRequirements()
    {
        return $this->container['requirements'];
    }

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

        return $this;
    }

    /**
     * Gets errors.
     *
     * @return FormulaErrorDto[]
     */
    public function getErrors()
    {
        return $this->container['errors'];
    }

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

        return $this;
    }

    /**
     * Gets ast.
     *
     * @return ParseFormulaResponseAst
     */
    public function getAst()
    {
        return $this->container['ast'];
    }

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

        return $this;
    }

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

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

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