<?php
/**
 * KitComponent
 *
 * PHP version 8.1
 *
 * @category Class
 * @package  Opsuite2
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * OpSuite API
 *
 * <p>Welcome the the OpSuite.API.  This swagger page is the best place to familiarize yourself with the API before you write any client code.  </p<p>Here is some general information about the use of the API.<p><p><b>Authentication</b><p>All requests require authentication. You will need a username and password in order to obtain a bearer token that is then used with all requests. If you do not have a username and password then contact the enterprise you are developing for.</p><p><b>Rate Limits</b><p><p>OpSuite.API is limited on a per client basis.<p><p>In order for your client to be allocated the correct rate limits you should add a header to your request with a Key of X-ClientId and a Value of your username.<p><p>You should then contact us so we can setup your rate limits.<p><p>If you do not set the X-ClientId header then your requests will be limited by a default set of low rates limits.<p><p>It is important that you use the API in the most efficient way so that you do not reach the rate limits.<p><p>Requests exceeding the limit will return a '429 Too Many Requests' along with a JSON error message.<p><p>A client's limits and usage are reported with every API request as part of the HTTP Headers.<p><p>Example successful response headers:<p><p>HTTP/1.1 200 OK<br>X-Rate-Limit: 24h<br>X-Rate-Limit-Remaining: 249963<br>X-Rate-Limit-Reset: 2022-11-25T09:20:41<p><p>Example rate-limited response JSON error message and headers:<p><p>Content: API calls quota exceeded! maximum admitted 4500 per 15m.<br>HTTP/1.1 429 Too many Requests<br>Retry-After: 10 (seconds)<p>
 *
 * The version of the OpenAPI document: v2
 * Contact: opsuitesupport@davrich.co.uk
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.13.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 Opsuite2\Model;

use \ArrayAccess;
use \Opsuite2\ObjectSerializer;

/**
 * KitComponent Class Doc Comment
 *
 * @category Class
 * @description The kit component information for an item
 * @package  Opsuite2
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 * @implements \ArrayAccess<string, mixed>
 */
class KitComponent implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'id' => 'int',
        'kit_item_master_id' => 'int',
        'component_item_master_id' => 'int',
        'component_sku' => 'string',
        'quantity' => 'float',
        'component_price_ex_tax' => 'float',
        'component_price_inc_tax' => 'float',
        'reason_code_id' => 'int'
    ];

    /**
      * 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 = [
        'id' => 'int32',
        'kit_item_master_id' => 'int32',
        'component_item_master_id' => 'int32',
        'component_sku' => null,
        'quantity' => 'double',
        'component_price_ex_tax' => 'double',
        'component_price_inc_tax' => 'double',
        'reason_code_id' => 'int32'
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'id' => false,
        'kit_item_master_id' => false,
        'component_item_master_id' => false,
        'component_sku' => true,
        'quantity' => false,
        'component_price_ex_tax' => true,
        'component_price_inc_tax' => true,
        'reason_code_id' => true
    ];

    /**
      * 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 = [
        'id' => 'id',
        'kit_item_master_id' => 'kitItemMasterId',
        'component_item_master_id' => 'componentItemMasterId',
        'component_sku' => 'componentSku',
        'quantity' => 'quantity',
        'component_price_ex_tax' => 'componentPriceExTax',
        'component_price_inc_tax' => 'componentPriceIncTax',
        'reason_code_id' => 'reasonCodeId'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'id' => 'setId',
        'kit_item_master_id' => 'setKitItemMasterId',
        'component_item_master_id' => 'setComponentItemMasterId',
        'component_sku' => 'setComponentSku',
        'quantity' => 'setQuantity',
        'component_price_ex_tax' => 'setComponentPriceExTax',
        'component_price_inc_tax' => 'setComponentPriceIncTax',
        'reason_code_id' => 'setReasonCodeId'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'id' => 'getId',
        'kit_item_master_id' => 'getKitItemMasterId',
        'component_item_master_id' => 'getComponentItemMasterId',
        'component_sku' => 'getComponentSku',
        'quantity' => 'getQuantity',
        'component_price_ex_tax' => 'getComponentPriceExTax',
        'component_price_inc_tax' => 'getComponentPriceIncTax',
        'reason_code_id' => 'getReasonCodeId'
    ];

    /**
     * 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('id', $data ?? [], null);
        $this->setIfExists('kit_item_master_id', $data ?? [], null);
        $this->setIfExists('component_item_master_id', $data ?? [], null);
        $this->setIfExists('component_sku', $data ?? [], null);
        $this->setIfExists('quantity', $data ?? [], null);
        $this->setIfExists('component_price_ex_tax', $data ?? [], null);
        $this->setIfExists('component_price_inc_tax', $data ?? [], null);
        $this->setIfExists('reason_code_id', $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 id
     *
     * @return int|null
     */
    public function getId()
    {
        return $this->container['id'];
    }

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

        return $this;
    }

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

    /**
     * Sets kit_item_master_id
     *
     * @param int|null $kit_item_master_id The id of the parent kit item
     *
     * @return self
     */
    public function setKitItemMasterId($kit_item_master_id)
    {
        if (is_null($kit_item_master_id)) {
            throw new \InvalidArgumentException('non-nullable kit_item_master_id cannot be null');
        }
        $this->container['kit_item_master_id'] = $kit_item_master_id;

        return $this;
    }

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

    /**
     * Sets component_item_master_id
     *
     * @param int|null $component_item_master_id The id of the component item
     *
     * @return self
     */
    public function setComponentItemMasterId($component_item_master_id)
    {
        if (is_null($component_item_master_id)) {
            throw new \InvalidArgumentException('non-nullable component_item_master_id cannot be null');
        }
        $this->container['component_item_master_id'] = $component_item_master_id;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets quantity
     *
     * @param float|null $quantity How many of the item are in the kit
     *
     * @return self
     */
    public function setQuantity($quantity)
    {
        if (is_null($quantity)) {
            throw new \InvalidArgumentException('non-nullable quantity cannot be null');
        }
        $this->container['quantity'] = $quantity;

        return $this;
    }

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

    /**
     * Sets component_price_ex_tax
     *
     * @param float|null $component_price_ex_tax The tax exclusive price of the item in the kit - only set for tax exclusive stores
     *
     * @return self
     */
    public function setComponentPriceExTax($component_price_ex_tax)
    {
        if (is_null($component_price_ex_tax)) {
            array_push($this->openAPINullablesSetToNull, 'component_price_ex_tax');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('component_price_ex_tax', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['component_price_ex_tax'] = $component_price_ex_tax;

        return $this;
    }

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

    /**
     * Sets component_price_inc_tax
     *
     * @param float|null $component_price_inc_tax The tax inclusive price of the item in the kit - only set for tax inclusive stores
     *
     * @return self
     */
    public function setComponentPriceIncTax($component_price_inc_tax)
    {
        if (is_null($component_price_inc_tax)) {
            array_push($this->openAPINullablesSetToNull, 'component_price_inc_tax');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('component_price_inc_tax', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['component_price_inc_tax'] = $component_price_inc_tax;

        return $this;
    }

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

    /**
     * Sets reason_code_id
     *
     * @param int|null $reason_code_id The reason code (optional)
     *
     * @return self
     */
    public function setReasonCodeId($reason_code_id)
    {
        if (is_null($reason_code_id)) {
            array_push($this->openAPINullablesSetToNull, 'reason_code_id');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('reason_code_id', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['reason_code_id'] = $reason_code_id;

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


