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

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

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

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'payment_intent_id' => 'string',
        'reason' => 'string',
        'register_sale_payment_id' => 'string',
        'status' => 'string',
        'transaction' => '\Vend202601\Model\LspayTransaction'
    ];

    /**
     * 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 = [
        'payment_intent_id' => null,
        'reason' => null,
        'register_sale_payment_id' => null,
        'status' => null,
        'transaction' => null
    ];

    /**
     * Array of nullable properties. Used for (de)serialization
     *
     * @var boolean[]
     */
    protected static array $openAPINullables = [
        'payment_intent_id' => false,
        'reason' => false,
        'register_sale_payment_id' => false,
        'status' => false,
        'transaction' => 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 = [
        'payment_intent_id' => 'payment_intent_id',
        'reason' => 'reason',
        'register_sale_payment_id' => 'register_sale_payment_id',
        'status' => 'status',
        'transaction' => 'transaction'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'payment_intent_id' => 'setPaymentIntentId',
        'reason' => 'setReason',
        'register_sale_payment_id' => 'setRegisterSalePaymentId',
        'status' => 'setStatus',
        'transaction' => 'setTransaction'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'payment_intent_id' => 'getPaymentIntentId',
        'reason' => 'getReason',
        'register_sale_payment_id' => 'getRegisterSalePaymentId',
        'status' => 'getStatus',
        'transaction' => 'getTransaction'
    ];

    /**
     * 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;
    }

    public const REASON_TERMINAL_BUSY = 'TERMINAL_BUSY';
    public const REASON_TERMINAL_TIMEOUT = 'TERMINAL_TIMEOUT';
    public const REASON_TERMINAL_UNAVAILABLE = 'TERMINAL_UNAVAILABLE';
    public const REASON_TERMINAL_ERROR = 'TERMINAL_ERROR';
    public const REASON_UNKNOWN = 'UNKNOWN';
    public const REASON_CARD_DECLINED = 'CARD_DECLINED';
    public const REASON_EXPIRED_CARD = 'EXPIRED_CARD';
    public const REASON_INSUFFICIENT_FUNDS = 'INSUFFICIENT_FUNDS';
    public const REASON_INVALID_AMOUNT = 'INVALID_AMOUNT';
    public const REASON_INVALID_ACCOUNT = 'INVALID_ACCOUNT';
    public const REASON_STRIPE_INVALID_REQUEST_ERROR = 'STRIPE_INVALID_REQUEST_ERROR';
    public const REASON_STRIPE_API_ERROR = 'STRIPE_API_ERROR';
    public const REASON_TRANSACTION_NOT_ALLOWED = 'TRANSACTION_NOT_ALLOWED';
    public const REASON_INCORRECT_PIN = 'INCORRECT_PIN';
    public const REASON_PIN_TRY_EXCEEDED = 'PIN_TRY_EXCEEDED';
    public const REASON_INTENT_CANCELLED = 'INTENT_CANCELLED';
    public const REASON_OVERRIDE_CANCELLED = 'OVERRIDE_CANCELLED';
    public const REASON_CUSTOMER_CANCELED = 'CUSTOMER_CANCELED';
    public const REASON_PAYMENT_INTENT_NOT_FOUND = 'PAYMENT_INTENT_NOT_FOUND';
    public const REASON_PAYMENT_METHOD_NOT_AVAILABLE = 'PAYMENT_METHOD_NOT_AVAILABLE';
    public const REASON_MOBILE_DEVICE_AUTHENTICATION_REQUIRED = 'MOBILE_DEVICE_AUTHENTICATION_REQUIRED';
    public const REASON_MISMATCH_INTENT = 'MISMATCH_INTENT';
    public const REASON_MISSING_PAYMENT_METHOD = 'MISSING_PAYMENT_METHOD';
    public const REASON_WRONG_RSPI = 'WRONG_RSPI';
    public const REASON_SETUP_INTENT_NOT_FOUND = 'SETUP_INTENT_NOT_FOUND';
    public const REASON_SETUP_INTENT_NOT_FAILED = 'SETUP_INTENT_NOT_FAILED';
    public const REASON_TERMINAL_ACTION_FAILED = 'TERMINAL_ACTION_FAILED';
    public const REASON_CARD_PRESENTED_MISMATCH_ORIGINAL_CARD = 'CARD_PRESENTED_MISMATCH_ORIGINAL_CARD';
    public const STATUS_CANCELLED = 'CANCELLED';
    public const STATUS_COMPLETED = 'COMPLETED';
    public const STATUS_DECLINED = 'DECLINED';
    public const STATUS_PROCESSING = 'PROCESSING';
    public const STATUS_AUTHORISED = 'AUTHORISED';
    public const STATUS_UNKNOWN = 'UNKNOWN';
    public const STATUS_CARD_PRESENTED = 'CARD_PRESENTED';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getReasonAllowableValues()
    {
        return [
            self::REASON_TERMINAL_BUSY,
            self::REASON_TERMINAL_TIMEOUT,
            self::REASON_TERMINAL_UNAVAILABLE,
            self::REASON_TERMINAL_ERROR,
            self::REASON_UNKNOWN,
            self::REASON_CARD_DECLINED,
            self::REASON_EXPIRED_CARD,
            self::REASON_INSUFFICIENT_FUNDS,
            self::REASON_INVALID_AMOUNT,
            self::REASON_INVALID_ACCOUNT,
            self::REASON_STRIPE_INVALID_REQUEST_ERROR,
            self::REASON_STRIPE_API_ERROR,
            self::REASON_TRANSACTION_NOT_ALLOWED,
            self::REASON_INCORRECT_PIN,
            self::REASON_PIN_TRY_EXCEEDED,
            self::REASON_INTENT_CANCELLED,
            self::REASON_OVERRIDE_CANCELLED,
            self::REASON_CUSTOMER_CANCELED,
            self::REASON_PAYMENT_INTENT_NOT_FOUND,
            self::REASON_PAYMENT_METHOD_NOT_AVAILABLE,
            self::REASON_MOBILE_DEVICE_AUTHENTICATION_REQUIRED,
            self::REASON_MISMATCH_INTENT,
            self::REASON_MISSING_PAYMENT_METHOD,
            self::REASON_WRONG_RSPI,
            self::REASON_SETUP_INTENT_NOT_FOUND,
            self::REASON_SETUP_INTENT_NOT_FAILED,
            self::REASON_TERMINAL_ACTION_FAILED,
            self::REASON_CARD_PRESENTED_MISMATCH_ORIGINAL_CARD,
        ];
    }

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getStatusAllowableValues()
    {
        return [
            self::STATUS_CANCELLED,
            self::STATUS_COMPLETED,
            self::STATUS_DECLINED,
            self::STATUS_PROCESSING,
            self::STATUS_AUTHORISED,
            self::STATUS_UNKNOWN,
            self::STATUS_CARD_PRESENTED,
        ];
    }

    /**
     * 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('payment_intent_id', $data ?? [], null);
        $this->setIfExists('reason', $data ?? [], null);
        $this->setIfExists('register_sale_payment_id', $data ?? [], null);
        $this->setIfExists('status', $data ?? [], null);
        $this->setIfExists('transaction', $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['payment_intent_id'] === null) {
            $invalidProperties[] = "'payment_intent_id' can't be null";
        }
        $allowedValues = $this->getReasonAllowableValues();
        if (!is_null($this->container['reason']) && !in_array($this->container['reason'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'reason', must be one of '%s'",
                $this->container['reason'],
                implode("', '", $allowedValues)
            );
        }

        if ($this->container['register_sale_payment_id'] === null) {
            $invalidProperties[] = "'register_sale_payment_id' can't be null";
        }
        if ($this->container['status'] === null) {
            $invalidProperties[] = "'status' can't be null";
        }
        $allowedValues = $this->getStatusAllowableValues();
        if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'status', must be one of '%s'",
                $this->container['status'],
                implode("', '", $allowedValues)
            );
        }

        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 payment_intent_id
     *
     * @return string
     */
    public function getPaymentIntentId()
    {
        return $this->container['payment_intent_id'];
    }

    /**
     * Sets payment_intent_id
     *
     * @param string $payment_intent_id The Stripe payment intent ID.
     *
     * @return self
     */
    public function setPaymentIntentId($payment_intent_id)
    {
        if (is_null($payment_intent_id)) {
            throw new \InvalidArgumentException('non-nullable payment_intent_id cannot be null');
        }
        $this->container['payment_intent_id'] = $payment_intent_id;

        return $this;
    }

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

    /**
     * Sets reason
     *
     * @param string|null $reason The reason for the transaction status.
     *
     * @return self
     */
    public function setReason($reason)
    {
        if (is_null($reason)) {
            throw new \InvalidArgumentException('non-nullable reason cannot be null');
        }
        $allowedValues = $this->getReasonAllowableValues();
        if (!in_array($reason, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'reason', must be one of '%s'",
                    $reason,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['reason'] = $reason;

        return $this;
    }

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

    /**
     * Sets register_sale_payment_id
     *
     * @param string $register_sale_payment_id The register sale payment ID.
     *
     * @return self
     */
    public function setRegisterSalePaymentId($register_sale_payment_id)
    {
        if (is_null($register_sale_payment_id)) {
            throw new \InvalidArgumentException('non-nullable register_sale_payment_id cannot be null');
        }
        $this->container['register_sale_payment_id'] = $register_sale_payment_id;

        return $this;
    }

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

    /**
     * Sets status
     *
     * @param string $status The cached transaction status.
     *
     * @return self
     */
    public function setStatus($status)
    {
        if (is_null($status)) {
            throw new \InvalidArgumentException('non-nullable status cannot be null');
        }
        $allowedValues = $this->getStatusAllowableValues();
        if (!in_array($status, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'status', must be one of '%s'",
                    $status,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['status'] = $status;

        return $this;
    }

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

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

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


