# coding: utf-8

"""
    用户全部 API 文档

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: v1
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class UserAccessToken(BaseModel):
    """
    用户令牌实体，用于管理用户的访问令牌及其相关信息。
    """ # noqa: E501
    id: Optional[StrictInt] = Field(default=None, description="用户令牌的唯一标识符。")
    user_id: Optional[StrictInt] = Field(default=None, description="与令牌关联的用户ID。", alias="userID")
    enable: Optional[StrictBool] = Field(default=None, description="指示令牌是否处于启用状态。")
    permissions: Optional[StrictStr] = Field(default=None, description="令牌拥有的权限列表，多个权限以逗号分隔。")
    title: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="令牌的标题或名称，用于标识令牌。")
    access_token: Optional[StrictStr] = Field(default=None, description="访问令牌的具体值，用于身份验证。", alias="accessToken")
    tags: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="用于分类或标记令牌的标签。")
    description: Optional[StrictStr] = Field(default=None, description="令牌的详细描述信息。")
    expire_time: Optional[datetime] = Field(default=None, description="令牌的过期时间，超过该时间令牌将失效。", alias="expireTime")
    create_date: Optional[datetime] = Field(default=None, description="令牌的创建日期，默认为当前时间。", alias="createDate")
    last_update: Optional[datetime] = Field(default=None, description="令牌的最后更新日期，默认为当前时间。", alias="lastUpdate")
    __properties: ClassVar[List[str]] = ["id", "userID", "enable", "permissions", "title", "accessToken", "tags", "description", "expireTime", "createDate", "lastUpdate"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of UserAccessToken from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if permissions (nullable) is None
        # and model_fields_set contains the field
        if self.permissions is None and "permissions" in self.model_fields_set:
            _dict['permissions'] = None

        # set to None if title (nullable) is None
        # and model_fields_set contains the field
        if self.title is None and "title" in self.model_fields_set:
            _dict['title'] = None

        # set to None if access_token (nullable) is None
        # and model_fields_set contains the field
        if self.access_token is None and "access_token" in self.model_fields_set:
            _dict['accessToken'] = None

        # set to None if tags (nullable) is None
        # and model_fields_set contains the field
        if self.tags is None and "tags" in self.model_fields_set:
            _dict['tags'] = None

        # set to None if description (nullable) is None
        # and model_fields_set contains the field
        if self.description is None and "description" in self.model_fields_set:
            _dict['description'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of UserAccessToken from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "userID": obj.get("userID"),
            "enable": obj.get("enable"),
            "permissions": obj.get("permissions"),
            "title": obj.get("title"),
            "accessToken": obj.get("accessToken"),
            "tags": obj.get("tags"),
            "description": obj.get("description"),
            "expireTime": obj.get("expireTime"),
            "createDate": obj.get("createDate"),
            "lastUpdate": obj.get("lastUpdate")
        })
        return _obj


