<?php
/**
 * BasketResponse
 *
 * 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;

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

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

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'credit_redemption' => '\Vend202601\Model\BasketResponseCreditRedemption',
        'items' => '\Vend202601\Model\BasketResponseItemsInner[]',
        'potential_promotions' => '\Vend202601\Model\BasketResponsePotentialPromotionsInner[]',
        'promo_code_validations' => '\Vend202601\Model\PromoCodeValidation[]',
        'request_id' => 'string',
        'sale_discount' => '\Vend202601\Model\BasketResponseSaleDiscount',
        'taxes' => '\Vend202601\Model\BasketTaxResponse[]',
        'totals' => '\Vend202601\Model\BasketResponseTotals'
    ];

    /**
     * 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 = [
        'credit_redemption' => null,
        'items' => null,
        'potential_promotions' => null,
        'promo_code_validations' => null,
        'request_id' => null,
        'sale_discount' => null,
        'taxes' => null,
        'totals' => null
    ];

    /**
     * Array of nullable properties. Used for (de)serialization
     *
     * @var boolean[]
     */
    protected static array $openAPINullables = [
        'credit_redemption' => true,
        'items' => false,
        'potential_promotions' => false,
        'promo_code_validations' => false,
        'request_id' => false,
        'sale_discount' => true,
        'taxes' => false,
        'totals' => 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 = [
        'credit_redemption' => 'credit_redemption',
        'items' => 'items',
        'potential_promotions' => 'potential_promotions',
        'promo_code_validations' => 'promo_code_validations',
        'request_id' => 'request_id',
        'sale_discount' => 'sale_discount',
        'taxes' => 'taxes',
        'totals' => 'totals'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'credit_redemption' => 'setCreditRedemption',
        'items' => 'setItems',
        'potential_promotions' => 'setPotentialPromotions',
        'promo_code_validations' => 'setPromoCodeValidations',
        'request_id' => 'setRequestId',
        'sale_discount' => 'setSaleDiscount',
        'taxes' => 'setTaxes',
        'totals' => 'setTotals'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'credit_redemption' => 'getCreditRedemption',
        'items' => 'getItems',
        'potential_promotions' => 'getPotentialPromotions',
        'promo_code_validations' => 'getPromoCodeValidations',
        'request_id' => 'getRequestId',
        'sale_discount' => 'getSaleDiscount',
        'taxes' => 'getTaxes',
        'totals' => 'getTotals'
    ];

    /**
     * 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('credit_redemption', $data ?? [], null);
        $this->setIfExists('items', $data ?? [], null);
        $this->setIfExists('potential_promotions', $data ?? [], null);
        $this->setIfExists('promo_code_validations', $data ?? [], null);
        $this->setIfExists('request_id', $data ?? [], null);
        $this->setIfExists('sale_discount', $data ?? [], null);
        $this->setIfExists('taxes', $data ?? [], null);
        $this->setIfExists('totals', $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['items'] === null) {
            $invalidProperties[] = "'items' can't be null";
        }
        if ($this->container['potential_promotions'] === null) {
            $invalidProperties[] = "'potential_promotions' can't be null";
        }
        if ($this->container['promo_code_validations'] === null) {
            $invalidProperties[] = "'promo_code_validations' can't be null";
        }
        if ($this->container['taxes'] === null) {
            $invalidProperties[] = "'taxes' can't be null";
        }
        if ($this->container['totals'] === null) {
            $invalidProperties[] = "'totals' 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 credit_redemption
     *
     * @return \Vend202601\Model\BasketResponseCreditRedemption|null
     */
    public function getCreditRedemption()
    {
        return $this->container['credit_redemption'];
    }

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

        return $this;
    }

    /**
     * Gets items
     *
     * @return \Vend202601\Model\BasketResponseItemsInner[]
     */
    public function getItems()
    {
        return $this->container['items'];
    }

    /**
     * Sets items
     *
     * @param \Vend202601\Model\BasketResponseItemsInner[] $items items
     *
     * @return self
     */
    public function setItems($items)
    {
        if (is_null($items)) {
            throw new \InvalidArgumentException('non-nullable items cannot be null');
        }
        $this->container['items'] = $items;

        return $this;
    }

    /**
     * Gets potential_promotions
     *
     * @return \Vend202601\Model\BasketResponsePotentialPromotionsInner[]
     */
    public function getPotentialPromotions()
    {
        return $this->container['potential_promotions'];
    }

    /**
     * Sets potential_promotions
     *
     * @param \Vend202601\Model\BasketResponsePotentialPromotionsInner[] $potential_promotions Promotions that could apply if additional conditions were met.
     *
     * @return self
     */
    public function setPotentialPromotions($potential_promotions)
    {
        if (is_null($potential_promotions)) {
            throw new \InvalidArgumentException('non-nullable potential_promotions cannot be null');
        }
        $this->container['potential_promotions'] = $potential_promotions;

        return $this;
    }

    /**
     * Gets promo_code_validations
     *
     * @return \Vend202601\Model\PromoCodeValidation[]
     */
    public function getPromoCodeValidations()
    {
        return $this->container['promo_code_validations'];
    }

    /**
     * Sets promo_code_validations
     *
     * @param \Vend202601\Model\PromoCodeValidation[] $promo_code_validations Validation result for each promo_code condition supplied.
     *
     * @return self
     */
    public function setPromoCodeValidations($promo_code_validations)
    {
        if (is_null($promo_code_validations)) {
            throw new \InvalidArgumentException('non-nullable promo_code_validations cannot be null');
        }
        $this->container['promo_code_validations'] = $promo_code_validations;

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets sale_discount
     *
     * @return \Vend202601\Model\BasketResponseSaleDiscount|null
     */
    public function getSaleDiscount()
    {
        return $this->container['sale_discount'];
    }

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

        return $this;
    }

    /**
     * Gets taxes
     *
     * @return \Vend202601\Model\BasketTaxResponse[]
     */
    public function getTaxes()
    {
        return $this->container['taxes'];
    }

    /**
     * Sets taxes
     *
     * @param \Vend202601\Model\BasketTaxResponse[] $taxes Aggregated tax breakdown across the basket.
     *
     * @return self
     */
    public function setTaxes($taxes)
    {
        if (is_null($taxes)) {
            throw new \InvalidArgumentException('non-nullable taxes cannot be null');
        }
        $this->container['taxes'] = $taxes;

        return $this;
    }

    /**
     * Gets totals
     *
     * @return \Vend202601\Model\BasketResponseTotals
     */
    public function getTotals()
    {
        return $this->container['totals'];
    }

    /**
     * Sets totals
     *
     * @param \Vend202601\Model\BasketResponseTotals $totals totals
     *
     * @return self
     */
    public function setTotals($totals)
    {
        if (is_null($totals)) {
            throw new \InvalidArgumentException('non-nullable totals cannot be null');
        }
        $this->container['totals'] = $totals;

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


