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

/**
 * API 2026-01
 *
 * Lightspeed Retail (X-Series) API.
 *
 * The version of the OpenAPI document: 2026-01
 * Contact: x-series.api@lightspeedhq.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.21.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 Vend202601\Model;

use \ArrayAccess;
use \Vend202601\ObjectSerializer;

/**
 * BasketProductResponse Class Doc Comment
 *
 * @category Class
 * @description Per-line-item product pricing result returned by the basket endpoint.
 * @package  Vend202601
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 * @implements \ArrayAccess<string, mixed>
 */
class BasketProductResponse implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'adjustments' => '\Vend202601\Model\BasketProductResponseAdjustmentsInner[]',
        'final_price' => 'string',
        'final_tax' => 'string',
        'id' => 'string',
        'loyalty_value' => 'string',
        'original_price' => 'string',
        'original_tax' => '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 = [
        'adjustments' => null,
        'final_price' => null,
        'final_tax' => null,
        'id' => null,
        'loyalty_value' => null,
        'original_price' => null,
        'original_tax' => null
    ];

    /**
     * Array of nullable properties. Used for (de)serialization
     *
     * @var boolean[]
     */
    protected static array $openAPINullables = [
        'adjustments' => false,
        'final_price' => false,
        'final_tax' => false,
        'id' => false,
        'loyalty_value' => false,
        'original_price' => false,
        'original_tax' => 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 = [
        'adjustments' => 'adjustments',
        'final_price' => 'final_price',
        'final_tax' => 'final_tax',
        'id' => 'id',
        'loyalty_value' => 'loyalty_value',
        'original_price' => 'original_price',
        'original_tax' => 'original_tax'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'adjustments' => 'setAdjustments',
        'final_price' => 'setFinalPrice',
        'final_tax' => 'setFinalTax',
        'id' => 'setId',
        'loyalty_value' => 'setLoyaltyValue',
        'original_price' => 'setOriginalPrice',
        'original_tax' => 'setOriginalTax'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'adjustments' => 'getAdjustments',
        'final_price' => 'getFinalPrice',
        'final_tax' => 'getFinalTax',
        'id' => 'getId',
        'loyalty_value' => 'getLoyaltyValue',
        'original_price' => 'getOriginalPrice',
        'original_tax' => 'getOriginalTax'
    ];

    /**
     * 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('adjustments', $data ?? [], null);
        $this->setIfExists('final_price', $data ?? [], null);
        $this->setIfExists('final_tax', $data ?? [], null);
        $this->setIfExists('id', $data ?? [], null);
        $this->setIfExists('loyalty_value', $data ?? [], null);
        $this->setIfExists('original_price', $data ?? [], null);
        $this->setIfExists('original_tax', $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 = [];

        if ($this->container['adjustments'] === null) {
            $invalidProperties[] = "'adjustments' can't be null";
        }
        if ($this->container['final_price'] === null) {
            $invalidProperties[] = "'final_price' can't be null";
        }
        if ($this->container['final_tax'] === null) {
            $invalidProperties[] = "'final_tax' can't be null";
        }
        if ($this->container['id'] === null) {
            $invalidProperties[] = "'id' can't be null";
        }
        if ($this->container['loyalty_value'] === null) {
            $invalidProperties[] = "'loyalty_value' can't be null";
        }
        if ($this->container['original_price'] === null) {
            $invalidProperties[] = "'original_price' can't be null";
        }
        if ($this->container['original_tax'] === null) {
            $invalidProperties[] = "'original_tax' 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 count($this->listInvalidProperties()) === 0;
    }


    /**
     * Gets adjustments
     *
     * @return \Vend202601\Model\BasketProductResponseAdjustmentsInner[]
     */
    public function getAdjustments()
    {
        return $this->container['adjustments'];
    }

    /**
     * Sets adjustments
     *
     * @param \Vend202601\Model\BasketProductResponseAdjustmentsInner[] $adjustments List of price adjustments applied to this product.
     *
     * @return self
     */
    public function setAdjustments($adjustments)
    {
        if (is_null($adjustments)) {
            throw new \InvalidArgumentException('non-nullable adjustments cannot be null');
        }
        $this->container['adjustments'] = $adjustments;

        return $this;
    }

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

    /**
     * Sets final_price
     *
     * @param string $final_price Final unit price after all adjustments (decimal string).
     *
     * @return self
     */
    public function setFinalPrice($final_price)
    {
        if (is_null($final_price)) {
            throw new \InvalidArgumentException('non-nullable final_price cannot be null');
        }
        $this->container['final_price'] = $final_price;

        return $this;
    }

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

    /**
     * Sets final_tax
     *
     * @param string $final_tax Final unit tax after all adjustments (decimal string).
     *
     * @return self
     */
    public function setFinalTax($final_tax)
    {
        if (is_null($final_tax)) {
            throw new \InvalidArgumentException('non-nullable final_tax cannot be null');
        }
        $this->container['final_tax'] = $final_tax;

        return $this;
    }

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

    /**
     * Sets id
     *
     * @param string $id The product ID.
     *
     * @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 loyalty_value
     *
     * @return string
     */
    public function getLoyaltyValue()
    {
        return $this->container['loyalty_value'];
    }

    /**
     * Sets loyalty_value
     *
     * @param string $loyalty_value Loyalty value earned for this product (decimal string).
     *
     * @return self
     */
    public function setLoyaltyValue($loyalty_value)
    {
        if (is_null($loyalty_value)) {
            throw new \InvalidArgumentException('non-nullable loyalty_value cannot be null');
        }
        $this->container['loyalty_value'] = $loyalty_value;

        return $this;
    }

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

    /**
     * Sets original_price
     *
     * @param string $original_price Original unit price before adjustments (decimal string).
     *
     * @return self
     */
    public function setOriginalPrice($original_price)
    {
        if (is_null($original_price)) {
            throw new \InvalidArgumentException('non-nullable original_price cannot be null');
        }
        $this->container['original_price'] = $original_price;

        return $this;
    }

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

    /**
     * Sets original_tax
     *
     * @param string $original_tax Original unit tax before adjustments (decimal string).
     *
     * @return self
     */
    public function setOriginalTax($original_tax)
    {
        if (is_null($original_tax)) {
            throw new \InvalidArgumentException('non-nullable original_tax cannot be null');
        }
        $this->container['original_tax'] = $original_tax;

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

    /**
     * Gets offset.
     *
     * @param integer|string $offset Offset
     *
     * @return mixed|null
     */
    #[\ReturnTypeWillChange]
    public function offsetGet(mixed $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|string $offset Offset
     *
     * @return void
     */
    public function offsetUnset(mixed $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));
    }
}


