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

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

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

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'amount' => 'float',
        'currency' => 'string',
        'discount' => '\Vend202601\Model\TransactionRequestDiscount',
        'idempotency_key' => 'string',
        'lspay_intent_id' => 'string',
        'lspay_payment_id' => 'string',
        'lspay_payment_method' => 'string',
        'lspay_refund_method' => 'string',
        'lspay_unreferenced_payment_method_id' => 'string',
        'original_register_sale_payment_id' => 'string',
        'outlet_id' => 'string',
        'pre_approval_code' => 'string',
        'product_version' => 'string',
        'products' => '\Vend202601\Model\TransactionRequestProductsInner[]',
        'register_name' => 'string',
        'wepay_payment_data' => 'array<string,mixed>'
    ];

    /**
     * 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 = [
        'amount' => 'double',
        'currency' => null,
        'discount' => null,
        'idempotency_key' => null,
        'lspay_intent_id' => null,
        'lspay_payment_id' => null,
        'lspay_payment_method' => null,
        'lspay_refund_method' => null,
        'lspay_unreferenced_payment_method_id' => null,
        'original_register_sale_payment_id' => null,
        'outlet_id' => null,
        'pre_approval_code' => null,
        'product_version' => null,
        'products' => null,
        'register_name' => null,
        'wepay_payment_data' => null
    ];

    /**
     * Array of nullable properties. Used for (de)serialization
     *
     * @var boolean[]
     */
    protected static array $openAPINullables = [
        'amount' => false,
        'currency' => false,
        'discount' => false,
        'idempotency_key' => false,
        'lspay_intent_id' => false,
        'lspay_payment_id' => false,
        'lspay_payment_method' => false,
        'lspay_refund_method' => false,
        'lspay_unreferenced_payment_method_id' => false,
        'original_register_sale_payment_id' => false,
        'outlet_id' => false,
        'pre_approval_code' => false,
        'product_version' => false,
        'products' => false,
        'register_name' => false,
        'wepay_payment_data' => 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 = [
        'amount' => 'amount',
        'currency' => 'currency',
        'discount' => 'discount',
        'idempotency_key' => 'idempotency_key',
        'lspay_intent_id' => 'lspay_intent_id',
        'lspay_payment_id' => 'lspay_payment_id',
        'lspay_payment_method' => 'lspay_payment_method',
        'lspay_refund_method' => 'lspay_refund_method',
        'lspay_unreferenced_payment_method_id' => 'lspay_unreferenced_payment_method_id',
        'original_register_sale_payment_id' => 'original_register_sale_payment_id',
        'outlet_id' => 'outlet_id',
        'pre_approval_code' => 'pre_approval_code',
        'product_version' => 'product_version',
        'products' => 'products',
        'register_name' => 'register_name',
        'wepay_payment_data' => 'wepay_payment_data'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'amount' => 'setAmount',
        'currency' => 'setCurrency',
        'discount' => 'setDiscount',
        'idempotency_key' => 'setIdempotencyKey',
        'lspay_intent_id' => 'setLspayIntentId',
        'lspay_payment_id' => 'setLspayPaymentId',
        'lspay_payment_method' => 'setLspayPaymentMethod',
        'lspay_refund_method' => 'setLspayRefundMethod',
        'lspay_unreferenced_payment_method_id' => 'setLspayUnreferencedPaymentMethodId',
        'original_register_sale_payment_id' => 'setOriginalRegisterSalePaymentId',
        'outlet_id' => 'setOutletId',
        'pre_approval_code' => 'setPreApprovalCode',
        'product_version' => 'setProductVersion',
        'products' => 'setProducts',
        'register_name' => 'setRegisterName',
        'wepay_payment_data' => 'setWepayPaymentData'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'amount' => 'getAmount',
        'currency' => 'getCurrency',
        'discount' => 'getDiscount',
        'idempotency_key' => 'getIdempotencyKey',
        'lspay_intent_id' => 'getLspayIntentId',
        'lspay_payment_id' => 'getLspayPaymentId',
        'lspay_payment_method' => 'getLspayPaymentMethod',
        'lspay_refund_method' => 'getLspayRefundMethod',
        'lspay_unreferenced_payment_method_id' => 'getLspayUnreferencedPaymentMethodId',
        'original_register_sale_payment_id' => 'getOriginalRegisterSalePaymentId',
        'outlet_id' => 'getOutletId',
        'pre_approval_code' => 'getPreApprovalCode',
        'product_version' => 'getProductVersion',
        'products' => 'getProducts',
        'register_name' => 'getRegisterName',
        'wepay_payment_data' => 'getWepayPaymentData'
    ];

    /**
     * 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('amount', $data ?? [], null);
        $this->setIfExists('currency', $data ?? [], null);
        $this->setIfExists('discount', $data ?? [], null);
        $this->setIfExists('idempotency_key', $data ?? [], null);
        $this->setIfExists('lspay_intent_id', $data ?? [], null);
        $this->setIfExists('lspay_payment_id', $data ?? [], null);
        $this->setIfExists('lspay_payment_method', $data ?? [], null);
        $this->setIfExists('lspay_refund_method', $data ?? [], null);
        $this->setIfExists('lspay_unreferenced_payment_method_id', $data ?? [], null);
        $this->setIfExists('original_register_sale_payment_id', $data ?? [], null);
        $this->setIfExists('outlet_id', $data ?? [], null);
        $this->setIfExists('pre_approval_code', $data ?? [], null);
        $this->setIfExists('product_version', $data ?? [], null);
        $this->setIfExists('products', $data ?? [], null);
        $this->setIfExists('register_name', $data ?? [], null);
        $this->setIfExists('wepay_payment_data', $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['amount'] === null) {
            $invalidProperties[] = "'amount' 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 amount
     *
     * @return float
     */
    public function getAmount()
    {
        return $this->container['amount'];
    }

    /**
     * Sets amount
     *
     * @param float $amount Payment amount. Must be non-zero. Negative values are only valid for refund requests
     *
     * @return self
     */
    public function setAmount($amount)
    {
        if (is_null($amount)) {
            throw new \InvalidArgumentException('non-nullable amount cannot be null');
        }
        $this->container['amount'] = $amount;

        return $this;
    }

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

    /**
     * Sets currency
     *
     * @param string|null $currency ISO 4217 currency code. Uppercased internally.
     *
     * @return self
     */
    public function setCurrency($currency)
    {
        if (is_null($currency)) {
            throw new \InvalidArgumentException('non-nullable currency cannot be null');
        }
        $this->container['currency'] = $currency;

        return $this;
    }

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

    /**
     * Sets discount
     *
     * @param \Vend202601\Model\TransactionRequestDiscount|null $discount discount
     *
     * @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 idempotency_key
     *
     * @return string|null
     */
    public function getIdempotencyKey()
    {
        return $this->container['idempotency_key'];
    }

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

        return $this;
    }

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

    /**
     * Sets lspay_intent_id
     *
     * @param string|null $lspay_intent_id LSPay Stripe payment intent ID. When set on a non-refund request, triggers the LSPay-specific payment path.
     *
     * @return self
     */
    public function setLspayIntentId($lspay_intent_id)
    {
        if (is_null($lspay_intent_id)) {
            throw new \InvalidArgumentException('non-nullable lspay_intent_id cannot be null');
        }
        $this->container['lspay_intent_id'] = $lspay_intent_id;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets lspay_payment_method
     *
     * @param string|null $lspay_payment_method Payment method used. LSPay only.
     *
     * @return self
     */
    public function setLspayPaymentMethod($lspay_payment_method)
    {
        if (is_null($lspay_payment_method)) {
            throw new \InvalidArgumentException('non-nullable lspay_payment_method cannot be null');
        }
        $this->container['lspay_payment_method'] = $lspay_payment_method;

        return $this;
    }

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

    /**
     * Sets lspay_refund_method
     *
     * @param string|null $lspay_refund_method Refund method. LSPay refunds only.
     *
     * @return self
     */
    public function setLspayRefundMethod($lspay_refund_method)
    {
        if (is_null($lspay_refund_method)) {
            throw new \InvalidArgumentException('non-nullable lspay_refund_method cannot be null');
        }
        $this->container['lspay_refund_method'] = $lspay_refund_method;

        return $this;
    }

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

    /**
     * Sets lspay_unreferenced_payment_method_id
     *
     * @param string|null $lspay_unreferenced_payment_method_id Unreferenced payment method ID for LSPay.
     *
     * @return self
     */
    public function setLspayUnreferencedPaymentMethodId($lspay_unreferenced_payment_method_id)
    {
        if (is_null($lspay_unreferenced_payment_method_id)) {
            throw new \InvalidArgumentException('non-nullable lspay_unreferenced_payment_method_id cannot be null');
        }
        $this->container['lspay_unreferenced_payment_method_id'] = $lspay_unreferenced_payment_method_id;

        return $this;
    }

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

    /**
     * Sets original_register_sale_payment_id
     *
     * @param string|null $original_register_sale_payment_id For refunds — the register sale payment ID of the original sale.
     *
     * @return self
     */
    public function setOriginalRegisterSalePaymentId($original_register_sale_payment_id)
    {
        if (is_null($original_register_sale_payment_id)) {
            throw new \InvalidArgumentException('non-nullable original_register_sale_payment_id cannot be null');
        }
        $this->container['original_register_sale_payment_id'] = $original_register_sale_payment_id;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets pre_approval_code
     *
     * @param string|null $pre_approval_code Pre-approval code. Afterpay only (deprecated).
     *
     * @return self
     */
    public function setPreApprovalCode($pre_approval_code)
    {
        if (is_null($pre_approval_code)) {
            throw new \InvalidArgumentException('non-nullable pre_approval_code cannot be null');
        }
        $this->container['pre_approval_code'] = $pre_approval_code;

        return $this;
    }

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

    /**
     * Sets product_version
     *
     * @param string|null $product_version POS product version. LSPay only.
     *
     * @return self
     */
    public function setProductVersion($product_version)
    {
        if (is_null($product_version)) {
            throw new \InvalidArgumentException('non-nullable product_version cannot be null');
        }
        $this->container['product_version'] = $product_version;

        return $this;
    }

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

    /**
     * Sets products
     *
     * @param \Vend202601\Model\TransactionRequestProductsInner[]|null $products Line items for providers that require product details (e.g. Klarna).
     *
     * @return self
     */
    public function setProducts($products)
    {
        if (is_null($products)) {
            throw new \InvalidArgumentException('non-nullable products cannot be null');
        }
        $this->container['products'] = $products;

        return $this;
    }

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

    /**
     * Sets register_name
     *
     * @param string|null $register_name Name of the register. LSPay only.
     *
     * @return self
     */
    public function setRegisterName($register_name)
    {
        if (is_null($register_name)) {
            throw new \InvalidArgumentException('non-nullable register_name cannot be null');
        }
        $this->container['register_name'] = $register_name;

        return $this;
    }

    /**
     * Gets wepay_payment_data
     *
     * @return array<string,mixed>|null
     */
    public function getWepayPaymentData()
    {
        return $this->container['wepay_payment_data'];
    }

    /**
     * Sets wepay_payment_data
     *
     * @param array<string,mixed>|null $wepay_payment_data WePay-specific payment data fields.
     *
     * @return self
     */
    public function setWepayPaymentData($wepay_payment_data)
    {
        if (is_null($wepay_payment_data)) {
            throw new \InvalidArgumentException('non-nullable wepay_payment_data cannot be null');
        }
        $this->container['wepay_payment_data'] = $wepay_payment_data;

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


