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

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

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

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'components' => 'string',
        'created_at' => '\DateTime',
        'is_used' => 'bool',
        'product_handle' => 'string',
        'product_price_point_handle' => 'string',
        'retailer_id' => 'string',
        'return_url' => 'string',
        'subscription_id' => 'int',
        'token' => 'string',
        'used_at' => '\DateTime',
        'vend_application_id' => 'string'
    ];

    /**
     * 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 = [
        'components' => null,
        'created_at' => 'date-time',
        'is_used' => null,
        'product_handle' => null,
        'product_price_point_handle' => null,
        'retailer_id' => null,
        'return_url' => null,
        'subscription_id' => 'int64',
        'token' => null,
        'used_at' => 'date-time',
        'vend_application_id' => null
    ];

    /**
     * Array of nullable properties. Used for (de)serialization
     *
     * @var boolean[]
     */
    protected static array $openAPINullables = [
        'components' => false,
        'created_at' => false,
        'is_used' => false,
        'product_handle' => false,
        'product_price_point_handle' => false,
        'retailer_id' => false,
        'return_url' => false,
        'subscription_id' => false,
        'token' => false,
        'used_at' => false,
        'vend_application_id' => 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 = [
        'components' => 'components',
        'created_at' => 'created_at',
        'is_used' => 'is_used',
        'product_handle' => 'product_handle',
        'product_price_point_handle' => 'product_price_point_handle',
        'retailer_id' => 'retailer_id',
        'return_url' => 'return_url',
        'subscription_id' => 'subscription_id',
        'token' => 'token',
        'used_at' => 'used_at',
        'vend_application_id' => 'vend_application_id'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'components' => 'setComponents',
        'created_at' => 'setCreatedAt',
        'is_used' => 'setIsUsed',
        'product_handle' => 'setProductHandle',
        'product_price_point_handle' => 'setProductPricePointHandle',
        'retailer_id' => 'setRetailerId',
        'return_url' => 'setReturnUrl',
        'subscription_id' => 'setSubscriptionId',
        'token' => 'setToken',
        'used_at' => 'setUsedAt',
        'vend_application_id' => 'setVendApplicationId'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'components' => 'getComponents',
        'created_at' => 'getCreatedAt',
        'is_used' => 'getIsUsed',
        'product_handle' => 'getProductHandle',
        'product_price_point_handle' => 'getProductPricePointHandle',
        'retailer_id' => 'getRetailerId',
        'return_url' => 'getReturnUrl',
        'subscription_id' => 'getSubscriptionId',
        'token' => 'getToken',
        'used_at' => 'getUsedAt',
        'vend_application_id' => 'getVendApplicationId'
    ];

    /**
     * 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('components', $data ?? [], null);
        $this->setIfExists('created_at', $data ?? [], null);
        $this->setIfExists('is_used', $data ?? [], null);
        $this->setIfExists('product_handle', $data ?? [], null);
        $this->setIfExists('product_price_point_handle', $data ?? [], null);
        $this->setIfExists('retailer_id', $data ?? [], null);
        $this->setIfExists('return_url', $data ?? [], null);
        $this->setIfExists('subscription_id', $data ?? [], null);
        $this->setIfExists('token', $data ?? [], null);
        $this->setIfExists('used_at', $data ?? [], null);
        $this->setIfExists('vend_application_id', $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 (!is_null($this->container['token']) && (mb_strlen($this->container['token']) > 32)) {
            $invalidProperties[] = "invalid value for 'token', the character length must be smaller than or equal to 32.";
        }

        if (!is_null($this->container['token']) && (mb_strlen($this->container['token']) < 32)) {
            $invalidProperties[] = "invalid value for 'token', the character length must be bigger than or equal to 32.";
        }

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

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

        return $this;
    }

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

    /**
     * Sets created_at
     *
     * @param \DateTime|null $created_at created_at
     *
     * @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 is_used
     *
     * @return bool|null
     */
    public function getIsUsed()
    {
        return $this->container['is_used'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets token
     *
     * @param string|null $token Token is a randomly generated string that is a required parameter for consent page
     *
     * @return self
     */
    public function setToken($token)
    {
        if (is_null($token)) {
            throw new \InvalidArgumentException('non-nullable token cannot be null');
        }
        if ((mb_strlen($token) > 32)) {
            throw new \InvalidArgumentException('invalid length for $token when calling PartnerSubscriptionToken., must be smaller than or equal to 32.');
        }
        if ((mb_strlen($token) < 32)) {
            throw new \InvalidArgumentException('invalid length for $token when calling PartnerSubscriptionToken., must be bigger than or equal to 32.');
        }

        $this->container['token'] = $token;

        return $this;
    }

    /**
     * Gets used_at
     *
     * @return \DateTime|null
     */
    public function getUsedAt()
    {
        return $this->container['used_at'];
    }

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

        return $this;
    }

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

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

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


