<?php
/**
 * ConfigItem
 *
 * PHP version 7.4
 *
 * @category Class
 * @package  Linnworks\Channel
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * linnworks_channel
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 1.0
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.11.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 Linnworks\Channel\Model;

use \ArrayAccess;
use \Linnworks\Channel\ObjectSerializer;

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'config_item_id' => 'string',
        'name' => 'string',
        'description' => 'string',
        'group_name' => 'string',
        'sort_order' => 'int',
        'selected_value' => 'string',
        'reg_ex_validation' => 'string',
        'reg_ex_error' => 'string',
        'must_be_specified' => 'bool',
        'read_only' => 'bool',
        'list_values' => 'string[]',
        'value_type' => '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 = [
        'config_item_id' => null,
        'name' => null,
        'description' => null,
        'group_name' => null,
        'sort_order' => null,
        'selected_value' => null,
        'reg_ex_validation' => null,
        'reg_ex_error' => null,
        'must_be_specified' => null,
        'read_only' => null,
        'list_values' => null,
        'value_type' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'config_item_id' => false,
        'name' => false,
        'description' => false,
        'group_name' => false,
        'sort_order' => false,
        'selected_value' => false,
        'reg_ex_validation' => true,
        'reg_ex_error' => true,
        'must_be_specified' => false,
        'read_only' => false,
        'list_values' => false,
        'value_type' => false
    ];

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

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

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

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

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

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

    /**
     * Checks if a nullable property is set to null.
     *
     * @param string $property
     * @return bool
     */
    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
     *
     * @var string[]
     */
    protected static $attributeMap = [
        'config_item_id' => 'ConfigItemId',
        'name' => 'Name',
        'description' => 'Description',
        'group_name' => 'GroupName',
        'sort_order' => 'SortOrder',
        'selected_value' => 'SelectedValue',
        'reg_ex_validation' => 'RegExValidation',
        'reg_ex_error' => 'RegExError',
        'must_be_specified' => 'MustBeSpecified',
        'read_only' => 'ReadOnly',
        'list_values' => 'ListValues',
        'value_type' => 'ValueType'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'config_item_id' => 'setConfigItemId',
        'name' => 'setName',
        'description' => 'setDescription',
        'group_name' => 'setGroupName',
        'sort_order' => 'setSortOrder',
        'selected_value' => 'setSelectedValue',
        'reg_ex_validation' => 'setRegExValidation',
        'reg_ex_error' => 'setRegExError',
        'must_be_specified' => 'setMustBeSpecified',
        'read_only' => 'setReadOnly',
        'list_values' => 'setListValues',
        'value_type' => 'setValueType'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'config_item_id' => 'getConfigItemId',
        'name' => 'getName',
        'description' => 'getDescription',
        'group_name' => 'getGroupName',
        'sort_order' => 'getSortOrder',
        'selected_value' => 'getSelectedValue',
        'reg_ex_validation' => 'getRegExValidation',
        'reg_ex_error' => 'getRegExError',
        'must_be_specified' => 'getMustBeSpecified',
        'read_only' => 'getReadOnly',
        'list_values' => 'getListValues',
        'value_type' => 'getValueType'
    ];

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


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

    /**
     * Constructor
     *
     * @param mixed[]|null $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('config_item_id', $data ?? [], null);
        $this->setIfExists('name', $data ?? [], null);
        $this->setIfExists('description', $data ?? [], null);
        $this->setIfExists('group_name', $data ?? [], null);
        $this->setIfExists('sort_order', $data ?? [], null);
        $this->setIfExists('selected_value', $data ?? [], null);
        $this->setIfExists('reg_ex_validation', $data ?? [], null);
        $this->setIfExists('reg_ex_error', $data ?? [], null);
        $this->setIfExists('must_be_specified', $data ?? [], null);
        $this->setIfExists('read_only', $data ?? [], null);
        $this->setIfExists('list_values', $data ?? [], null);
        $this->setIfExists('value_type', $data ?? [], null);
    }

    /**
    * 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 string $variableName
    * @param array  $fields
    * @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;
    }

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

        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 count($this->listInvalidProperties()) === 0;
    }


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

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

        return $this;
    }

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

    /**
     * Sets name
     *
     * @param string|null $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 description
     *
     * @return string|null
     */
    public function getDescription()
    {
        return $this->container['description'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets sort_order
     *
     * @return int|null
     */
    public function getSortOrder()
    {
        return $this->container['sort_order'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

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

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

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

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

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     * @link 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 the string presentation of the object
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

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


