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

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

use \ArrayAccess;
use \Vend\ObjectSerializer;

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

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

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'adjustment' => 'float',
        'adjustment_type' => 'string',
        'created_at' => 'string',
        'default_display_price' => 'float',
        'deleted_at' => 'string',
        'discount' => 'float',
        'id' => 'string',
        'loyalty_value' => 'float',
        'max_units' => 'float',
        'min_units' => 'float',
        'price' => 'float',
        'price_book_id' => 'string',
        'product_id' => 'string',
        'retail_tax' => 'float',
        'rounding' => 'string',
        'tax_id' => 'string',
        'updated_at' => 'string',
        'version' => '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 = [
        'adjustment' => 'double',
        'adjustment_type' => null,
        'created_at' => null,
        'default_display_price' => 'double',
        'deleted_at' => null,
        'discount' => 'double',
        'id' => null,
        'loyalty_value' => 'double',
        'max_units' => 'double',
        'min_units' => 'double',
        'price' => 'double',
        'price_book_id' => null,
        'product_id' => null,
        'retail_tax' => 'double',
        'rounding' => null,
        'tax_id' => null,
        'updated_at' => null,
        'version' => 'int64'
    ];

    /**
     * Array of nullable properties. Used for (de)serialization
     *
     * @var boolean[]
     */
    protected static array $openAPINullables = [
        'adjustment' => false,
        'adjustment_type' => false,
        'created_at' => false,
        'default_display_price' => false,
        'deleted_at' => true,
        'discount' => false,
        'id' => false,
        'loyalty_value' => true,
        'max_units' => true,
        'min_units' => true,
        'price' => false,
        'price_book_id' => false,
        'product_id' => false,
        'retail_tax' => false,
        'rounding' => false,
        'tax_id' => false,
        'updated_at' => false,
        'version' => 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 = [
        'adjustment' => 'adjustment',
        'adjustment_type' => 'adjustment_type',
        'created_at' => 'created_at',
        'default_display_price' => 'default_display_price',
        'deleted_at' => 'deleted_at',
        'discount' => 'discount',
        'id' => 'id',
        'loyalty_value' => 'loyalty_value',
        'max_units' => 'max_units',
        'min_units' => 'min_units',
        'price' => 'price',
        'price_book_id' => 'price_book_id',
        'product_id' => 'product_id',
        'retail_tax' => 'retail_tax',
        'rounding' => 'rounding',
        'tax_id' => 'tax_id',
        'updated_at' => 'updated_at',
        'version' => 'version'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'adjustment' => 'setAdjustment',
        'adjustment_type' => 'setAdjustmentType',
        'created_at' => 'setCreatedAt',
        'default_display_price' => 'setDefaultDisplayPrice',
        'deleted_at' => 'setDeletedAt',
        'discount' => 'setDiscount',
        'id' => 'setId',
        'loyalty_value' => 'setLoyaltyValue',
        'max_units' => 'setMaxUnits',
        'min_units' => 'setMinUnits',
        'price' => 'setPrice',
        'price_book_id' => 'setPriceBookId',
        'product_id' => 'setProductId',
        'retail_tax' => 'setRetailTax',
        'rounding' => 'setRounding',
        'tax_id' => 'setTaxId',
        'updated_at' => 'setUpdatedAt',
        'version' => 'setVersion'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'adjustment' => 'getAdjustment',
        'adjustment_type' => 'getAdjustmentType',
        'created_at' => 'getCreatedAt',
        'default_display_price' => 'getDefaultDisplayPrice',
        'deleted_at' => 'getDeletedAt',
        'discount' => 'getDiscount',
        'id' => 'getId',
        'loyalty_value' => 'getLoyaltyValue',
        'max_units' => 'getMaxUnits',
        'min_units' => 'getMinUnits',
        'price' => 'getPrice',
        'price_book_id' => 'getPriceBookId',
        'product_id' => 'getProductId',
        'retail_tax' => 'getRetailTax',
        'rounding' => 'getRounding',
        'tax_id' => 'getTaxId',
        'updated_at' => 'getUpdatedAt',
        'version' => 'getVersion'
    ];

    /**
     * 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('adjustment', $data ?? [], null);
        $this->setIfExists('adjustment_type', $data ?? [], null);
        $this->setIfExists('created_at', $data ?? [], null);
        $this->setIfExists('default_display_price', $data ?? [], null);
        $this->setIfExists('deleted_at', $data ?? [], null);
        $this->setIfExists('discount', $data ?? [], null);
        $this->setIfExists('id', $data ?? [], null);
        $this->setIfExists('loyalty_value', $data ?? [], null);
        $this->setIfExists('max_units', $data ?? [], null);
        $this->setIfExists('min_units', $data ?? [], null);
        $this->setIfExists('price', $data ?? [], null);
        $this->setIfExists('price_book_id', $data ?? [], null);
        $this->setIfExists('product_id', $data ?? [], null);
        $this->setIfExists('retail_tax', $data ?? [], null);
        $this->setIfExists('rounding', $data ?? [], null);
        $this->setIfExists('tax_id', $data ?? [], null);
        $this->setIfExists('updated_at', $data ?? [], null);
        $this->setIfExists('version', $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['price'] === null) {
            $invalidProperties[] = "'price' can't be null";
        }
        if ($this->container['product_id'] === null) {
            $invalidProperties[] = "'product_id' can't be null";
        }
        if ($this->container['tax_id'] === null) {
            $invalidProperties[] = "'tax_id' 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 adjustment
     *
     * @return float|null
     */
    public function getAdjustment()
    {
        return $this->container['adjustment'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets default_display_price
     *
     * @param float|null $default_display_price The default display price
     *
     * @return self
     */
    public function setDefaultDisplayPrice($default_display_price)
    {
        if (is_null($default_display_price)) {
            throw new \InvalidArgumentException('non-nullable default_display_price cannot be null');
        }
        $this->container['default_display_price'] = $default_display_price;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets id
     *
     * @param string|null $id Auto-generated object 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 float|null
     */
    public function getLoyaltyValue()
    {
        return $this->container['loyalty_value'];
    }

    /**
     * Sets loyalty_value
     *
     * @param float|null $loyalty_value Price Book defined loyalty value.
     *
     * @return self
     */
    public function setLoyaltyValue($loyalty_value)
    {
        if (is_null($loyalty_value)) {
            array_push($this->openAPINullablesSetToNull, 'loyalty_value');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('loyalty_value', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['loyalty_value'] = $loyalty_value;

        return $this;
    }

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

    /**
     * Sets max_units
     *
     * @param float|null $max_units The maximum number of items for which this price will be used.
     *
     * @return self
     */
    public function setMaxUnits($max_units)
    {
        if (is_null($max_units)) {
            array_push($this->openAPINullablesSetToNull, 'max_units');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('max_units', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['max_units'] = $max_units;

        return $this;
    }

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

    /**
     * Sets min_units
     *
     * @param float|null $min_units The minimum number of items for which this price will be used.
     *
     * @return self
     */
    public function setMinUnits($min_units)
    {
        if (is_null($min_units)) {
            array_push($this->openAPINullablesSetToNull, 'min_units');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('min_units', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['min_units'] = $min_units;

        return $this;
    }

    /**
     * Gets price
     *
     * @return float
     */
    public function getPrice()
    {
        return $this->container['price'];
    }

    /**
     * Sets price
     *
     * @param float $price The Retail price of the product.
     *
     * @return self
     */
    public function setPrice($price)
    {
        if (is_null($price)) {
            throw new \InvalidArgumentException('non-nullable price cannot be null');
        }
        $this->container['price'] = $price;

        return $this;
    }

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

    /**
     * Sets price_book_id
     *
     * @param string|null $price_book_id The ID of the Price Book this product belongs to.
     *
     * @return self
     */
    public function setPriceBookId($price_book_id)
    {
        if (is_null($price_book_id)) {
            throw new \InvalidArgumentException('non-nullable price_book_id cannot be null');
        }
        $this->container['price_book_id'] = $price_book_id;

        return $this;
    }

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

    /**
     * Sets product_id
     *
     * @param string $product_id The ID of the associated product.
     *
     * @return self
     */
    public function setProductId($product_id)
    {
        if (is_null($product_id)) {
            throw new \InvalidArgumentException('non-nullable product_id cannot be null');
        }
        $this->container['product_id'] = $product_id;

        return $this;
    }

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

    /**
     * Sets retail_tax
     *
     * @param float|null $retail_tax The retail tax
     *
     * @return self
     */
    public function setRetailTax($retail_tax)
    {
        if (is_null($retail_tax)) {
            throw new \InvalidArgumentException('non-nullable retail_tax cannot be null');
        }
        $this->container['retail_tax'] = $retail_tax;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets tax_id
     *
     * @param string $tax_id The id for the tax rate
     *
     * @return self
     */
    public function setTaxId($tax_id)
    {
        if (is_null($tax_id)) {
            throw new \InvalidArgumentException('non-nullable tax_id cannot be null');
        }
        $this->container['tax_id'] = $tax_id;

        return $this;
    }

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

    /**
     * Sets updated_at
     *
     * @param string|null $updated_at Last update timestamp in UTC.
     *
     * @return self
     */
    public function setUpdatedAt($updated_at)
    {
        if (is_null($updated_at)) {
            throw new \InvalidArgumentException('non-nullable updated_at cannot be null');
        }
        $this->container['updated_at'] = $updated_at;

        return $this;
    }

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

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

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


