<?php
/**
 * ResponseOpenAPITokensCountResult
 *
 * PHP version 7.4
 *
 * @category Class
 * @package  OpenAPI\Client
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * 碳丝路数据开放平台API
 *
 * 碳丝路数据开放平台
 *
 * The version of the OpenAPI document: 0.4.8
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 7.0.1
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace OpenAPI\Client\Model;

use \ArrayAccess;
use \OpenAPI\Client\ObjectSerializer;

/**
 * ResponseOpenAPITokensCountResult Class Doc Comment
 *
 * @category Class
 * @description 消息载体对象
 * @package  OpenAPI\Client
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 * @implements \ArrayAccess<string, mixed>
 */
class ResponseOpenAPITokensCountResult implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'time' => 'string',
        'openid' => 'string',
        'payload' => '\OpenAPI\Client\Model\TokensCountResult',
        'sign' => 'string',
        'charset' => 'string',
        'description' => 'string',
        'response_id' => 'string',
        'err_code' => 'int',
        'err_msg' => 'string',
        'sub_err' => 'int',
        'sub_msg' => 'string',
        'sign_type' => '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 = [
        'time' => null,
        'openid' => null,
        'payload' => null,
        'sign' => null,
        'charset' => null,
        'description' => null,
        'response_id' => null,
        'err_code' => 'int32',
        'err_msg' => null,
        'sub_err' => 'int32',
        'sub_msg' => null,
        'sign_type' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'time' => false,
		'openid' => false,
		'payload' => false,
		'sign' => false,
		'charset' => false,
		'description' => false,
		'response_id' => false,
		'err_code' => false,
		'err_msg' => false,
		'sub_err' => false,
		'sub_msg' => false,
		'sign_type' => 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 = [
        'time' => 'time',
        'openid' => 'openid',
        'payload' => 'payload',
        'sign' => 'sign',
        'charset' => 'charset',
        'description' => 'description',
        'response_id' => 'response_id',
        'err_code' => 'err_code',
        'err_msg' => 'err_msg',
        'sub_err' => 'sub_err',
        'sub_msg' => 'sub_msg',
        'sign_type' => 'sign_type'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'time' => 'setTime',
        'openid' => 'setOpenid',
        'payload' => 'setPayload',
        'sign' => 'setSign',
        'charset' => 'setCharset',
        'description' => 'setDescription',
        'response_id' => 'setResponseId',
        'err_code' => 'setErrCode',
        'err_msg' => 'setErrMsg',
        'sub_err' => 'setSubErr',
        'sub_msg' => 'setSubMsg',
        'sign_type' => 'setSignType'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'time' => 'getTime',
        'openid' => 'getOpenid',
        'payload' => 'getPayload',
        'sign' => 'getSign',
        'charset' => 'getCharset',
        'description' => 'getDescription',
        'response_id' => 'getResponseId',
        'err_code' => 'getErrCode',
        'err_msg' => 'getErrMsg',
        'sub_err' => 'getSubErr',
        'sub_msg' => 'getSubMsg',
        'sign_type' => 'getSignType'
    ];

    /**
     * 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[] $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(array $data = null)
    {
        $this->setIfExists('time', $data ?? [], null);
        $this->setIfExists('openid', $data ?? [], null);
        $this->setIfExists('payload', $data ?? [], null);
        $this->setIfExists('sign', $data ?? [], null);
        $this->setIfExists('charset', $data ?? [], null);
        $this->setIfExists('description', $data ?? [], null);
        $this->setIfExists('response_id', $data ?? [], null);
        $this->setIfExists('err_code', $data ?? [], null);
        $this->setIfExists('err_msg', $data ?? [], null);
        $this->setIfExists('sub_err', $data ?? [], null);
        $this->setIfExists('sub_msg', $data ?? [], null);
        $this->setIfExists('sign_type', $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 = [];

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

    /**
     * Sets time
     *
     * @param string|null $time 该消息发生的时间
     *
     * @return self
     */
    public function setTime($time)
    {
        if (is_null($time)) {
            throw new \InvalidArgumentException('non-nullable time cannot be null');
        }
        $this->container['time'] = $time;

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets payload
     *
     * @return \OpenAPI\Client\Model\TokensCountResult|null
     */
    public function getPayload()
    {
        return $this->container['payload'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets response_id
     *
     * @param string|null $response_id 消息的唯一ID
     *
     * @return self
     */
    public function setResponseId($response_id)
    {
        if (is_null($response_id)) {
            throw new \InvalidArgumentException('non-nullable response_id cannot be null');
        }
        $this->container['response_id'] = $response_id;

        return $this;
    }

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

    /**
     * Sets err_code
     *
     * @param int|null $err_code 该消息的错误码
     *
     * @return self
     */
    public function setErrCode($err_code)
    {
        if (is_null($err_code)) {
            throw new \InvalidArgumentException('non-nullable err_code cannot be null');
        }
        $this->container['err_code'] = $err_code;

        return $this;
    }

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

    /**
     * Sets err_msg
     *
     * @param string|null $err_msg 错误消息描述
     *
     * @return self
     */
    public function setErrMsg($err_msg)
    {
        if (is_null($err_msg)) {
            throw new \InvalidArgumentException('non-nullable err_msg cannot be null');
        }
        $this->container['err_msg'] = $err_msg;

        return $this;
    }

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

    /**
     * Sets sub_err
     *
     * @param int|null $sub_err 子错误的具体的代号
     *
     * @return self
     */
    public function setSubErr($sub_err)
    {
        if (is_null($sub_err)) {
            throw new \InvalidArgumentException('non-nullable sub_err cannot be null');
        }
        $this->container['sub_err'] = $sub_err;

        return $this;
    }

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

    /**
     * Sets sub_msg
     *
     * @param string|null $sub_msg 子错误对应的提示消息
     *
     * @return self
     */
    public function setSubMsg($sub_msg)
    {
        if (is_null($sub_msg)) {
            throw new \InvalidArgumentException('non-nullable sub_msg cannot be null');
        }
        $this->container['sub_msg'] = $sub_msg;

        return $this;
    }

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

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

        return $this;
    }
    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param integer $offset Offset
     *
     * @return boolean
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param integer $offset Offset
     *
     * @return mixed|null
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($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 $offset Offset
     *
     * @return void
     */
    public function offsetUnset($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));
    }
}