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

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

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

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'created_at' => '\DateTime',
        'id' => 'string',
        'payment_type_id' => 'string',
        'provider_fields' => 'array<string,mixed>',
        'register_id' => 'string',
        'register_sale_payment_id' => 'string',
        'retailer_id' => 'string',
        'retailer_payment_type_id' => 'string',
        'status' => 'string',
        'tenders' => '\Vend\Model\LspayTender[]',
        'updated_at' => '\DateTime'
    ];

    /**
     * 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 = [
        'created_at' => 'date-time',
        'id' => null,
        'payment_type_id' => null,
        'provider_fields' => null,
        'register_id' => null,
        'register_sale_payment_id' => null,
        'retailer_id' => null,
        'retailer_payment_type_id' => null,
        'status' => null,
        'tenders' => null,
        'updated_at' => 'date-time'
    ];

    /**
     * Array of nullable properties. Used for (de)serialization
     *
     * @var boolean[]
     */
    protected static array $openAPINullables = [
        'created_at' => false,
        'id' => false,
        'payment_type_id' => false,
        'provider_fields' => false,
        'register_id' => false,
        'register_sale_payment_id' => false,
        'retailer_id' => false,
        'retailer_payment_type_id' => false,
        'status' => false,
        'tenders' => false,
        'updated_at' => 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 = [
        'created_at' => 'created_at',
        'id' => 'id',
        'payment_type_id' => 'payment_type_id',
        'provider_fields' => 'provider_fields',
        'register_id' => 'register_id',
        'register_sale_payment_id' => 'register_sale_payment_id',
        'retailer_id' => 'retailer_id',
        'retailer_payment_type_id' => 'retailer_payment_type_id',
        'status' => 'status',
        'tenders' => 'tenders',
        'updated_at' => 'updated_at'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'created_at' => 'setCreatedAt',
        'id' => 'setId',
        'payment_type_id' => 'setPaymentTypeId',
        'provider_fields' => 'setProviderFields',
        'register_id' => 'setRegisterId',
        'register_sale_payment_id' => 'setRegisterSalePaymentId',
        'retailer_id' => 'setRetailerId',
        'retailer_payment_type_id' => 'setRetailerPaymentTypeId',
        'status' => 'setStatus',
        'tenders' => 'setTenders',
        'updated_at' => 'setUpdatedAt'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'created_at' => 'getCreatedAt',
        'id' => 'getId',
        'payment_type_id' => 'getPaymentTypeId',
        'provider_fields' => 'getProviderFields',
        'register_id' => 'getRegisterId',
        'register_sale_payment_id' => 'getRegisterSalePaymentId',
        'retailer_id' => 'getRetailerId',
        'retailer_payment_type_id' => 'getRetailerPaymentTypeId',
        'status' => 'getStatus',
        'tenders' => 'getTenders',
        'updated_at' => 'getUpdatedAt'
    ];

    /**
     * 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 STATUS_CANCELLED = 'CANCELLED';
    public const STATUS_CANCELLED_BAD_CARD = 'CANCELLED_BAD_CARD';
    public const STATUS_CANCELLED_BUSY = 'CANCELLED_BUSY';
    public const STATUS_COMPLETED = 'COMPLETED';
    public const STATUS_DECLINED = 'DECLINED';
    public const STATUS_REFUNDED = 'REFUNDED';
    public const STATUS_REVERSED = 'REVERSED';
    public const STATUS_TIMEOUT = 'TIMEOUT';
    public const STATUS_UNKNOWN = 'UNKNOWN';
    public const STATUS_PROCESSING = 'PROCESSING';

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

    /**
     * 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('created_at', $data ?? [], null);
        $this->setIfExists('id', $data ?? [], null);
        $this->setIfExists('payment_type_id', $data ?? [], null);
        $this->setIfExists('provider_fields', $data ?? [], null);
        $this->setIfExists('register_id', $data ?? [], null);
        $this->setIfExists('register_sale_payment_id', $data ?? [], null);
        $this->setIfExists('retailer_id', $data ?? [], null);
        $this->setIfExists('retailer_payment_type_id', $data ?? [], null);
        $this->setIfExists('status', $data ?? [], null);
        $this->setIfExists('tenders', $data ?? [], null);
        $this->setIfExists('updated_at', $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['created_at'] === null) {
            $invalidProperties[] = "'created_at' can't be null";
        }
        if ($this->container['id'] === null) {
            $invalidProperties[] = "'id' can't be null";
        }
        if ($this->container['provider_fields'] === null) {
            $invalidProperties[] = "'provider_fields' can't be null";
        }
        if ($this->container['register_id'] === null) {
            $invalidProperties[] = "'register_id' can't be null";
        }
        if ($this->container['register_sale_payment_id'] === null) {
            $invalidProperties[] = "'register_sale_payment_id' can't be null";
        }
        if ($this->container['retailer_id'] === null) {
            $invalidProperties[] = "'retailer_id' can't be null";
        }
        if ($this->container['retailer_payment_type_id'] === null) {
            $invalidProperties[] = "'retailer_payment_type_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)
            );
        }

        if ($this->container['tenders'] === null) {
            $invalidProperties[] = "'tenders' can't be null";
        }
        if ($this->container['updated_at'] === null) {
            $invalidProperties[] = "'updated_at' 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 created_at
     *
     * @return \DateTime
     */
    public function getCreatedAt()
    {
        return $this->container['created_at'];
    }

    /**
     * Sets created_at
     *
     * @param \DateTime $created_at The time the transaction was created.
     *
     * @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 id
     *
     * @return string
     */
    public function getId()
    {
        return $this->container['id'];
    }

    /**
     * Sets id
     *
     * @param string $id The transaction 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 payment_type_id
     *
     * @return string|null
     */
    public function getPaymentTypeId()
    {
        return $this->container['payment_type_id'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets status
     *
     * @param string $status The 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 tenders
     *
     * @return \Vend\Model\LspayTender[]
     */
    public function getTenders()
    {
        return $this->container['tenders'];
    }

    /**
     * Sets tenders
     *
     * @param \Vend\Model\LspayTender[] $tenders The tenders associated with this transaction.
     *
     * @return self
     */
    public function setTenders($tenders)
    {
        if (is_null($tenders)) {
            throw new \InvalidArgumentException('non-nullable tenders cannot be null');
        }
        $this->container['tenders'] = $tenders;

        return $this;
    }

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

    /**
     * Sets updated_at
     *
     * @param \DateTime $updated_at The time the transaction was last updated.
     *
     * @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;
    }
    /**
     * 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));
    }
}


