<?php

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

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

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

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'ok' => 'bool',
        'name' => 'string',
        'signatureId' => 'string',
        'value' => 'mixed',
        'valueKind' => 'string',
        'valueObjectKind' => 'string',
        'warnings' => '\EdgeBox\SyncCore\V2\Raw\Model\FormulaWarningDto[]',
        'error' => 'FormulaExecutionErrorDto',
        'children' => '\EdgeBox\SyncCore\V2\Raw\Model\FormulaNodeOutputDto[]',
        'nodeId' => 'string',
        'span' => 'FormulaSpanDto',
        'skipped' => '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 = [
        'ok' => null,
        'name' => null,
        'signatureId' => null,
        'value' => null,
        'valueKind' => null,
        'valueObjectKind' => null,
        'warnings' => null,
        'error' => null,
        'children' => null,
        'nodeId' => null,
        'span' => null,
        'skipped' => null,
    ];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'ok' => false,
        'name' => false,
        'signatureId' => true,
        'value' => true,
        'valueKind' => true,
        'valueObjectKind' => true,
        'warnings' => true,
        'error' => true,
        'children' => false,
        'nodeId' => true,
        'span' => true,
        'skipped' => 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 = [
        'ok' => 'ok',
        'name' => 'name',
        'signatureId' => 'signatureId',
        'value' => 'value',
        'valueKind' => 'valueKind',
        'valueObjectKind' => 'valueObjectKind',
        'warnings' => 'warnings',
        'error' => 'error',
        'children' => 'children',
        'nodeId' => 'nodeId',
        'span' => 'span',
        'skipped' => 'skipped',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static $setters = [
        'ok' => 'setOk',
        'name' => 'setName',
        'signatureId' => 'setSignatureId',
        'value' => 'setValue',
        'valueKind' => 'setValueKind',
        'valueObjectKind' => 'setValueObjectKind',
        'warnings' => 'setWarnings',
        'error' => 'setError',
        'children' => 'setChildren',
        'nodeId' => 'setNodeId',
        'span' => 'setSpan',
        'skipped' => 'setSkipped',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static $getters = [
        'ok' => 'getOk',
        'name' => 'getName',
        'signatureId' => 'getSignatureId',
        'value' => 'getValue',
        'valueKind' => 'getValueKind',
        'valueObjectKind' => 'getValueObjectKind',
        'warnings' => 'getWarnings',
        'error' => 'getError',
        'children' => 'getChildren',
        'nodeId' => 'getNodeId',
        'span' => 'getSpan',
        'skipped' => 'getSkipped',
    ];

    /**
     * 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('name', $data ?? [], null);
        $this->setIfExists('signatureId', $data ?? [], null);
        $this->setIfExists('value', $data ?? [], null);
        $this->setIfExists('valueKind', $data ?? [], null);
        $this->setIfExists('valueObjectKind', $data ?? [], null);
        $this->setIfExists('warnings', $data ?? [], null);
        $this->setIfExists('error', $data ?? [], null);
        $this->setIfExists('children', $data ?? [], null);
        $this->setIfExists('nodeId', $data ?? [], null);
        $this->setIfExists('span', $data ?? [], null);
        $this->setIfExists('skipped', $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['name']) {
            $invalidProperties[] = "'name' can't be null";
        }
        if (null === $this->container['children']) {
            $invalidProperties[] = "'children' 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 name.
     *
     * @return string
     */
    public function getName()
    {
        return $this->container['name'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets warnings.
     *
     * @return null|FormulaWarningDto[]
     */
    public function getWarnings()
    {
        return $this->container['warnings'];
    }

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

        return $this;
    }

    /**
     * Gets error.
     *
     * @return null|FormulaExecutionErrorDto
     */
    public function getError()
    {
        return $this->container['error'];
    }

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

        return $this;
    }

    /**
     * Gets children.
     *
     * @return FormulaNodeOutputDto[]
     */
    public function getChildren()
    {
        return $this->container['children'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets span.
     *
     * @return null|FormulaSpanDto
     */
    public function getSpan()
    {
        return $this->container['span'];
    }

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

        return $this;
    }

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

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

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