# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class Order(BaseModel):
    """
    订单实体，用于记录用户的订单信息。
    """ # noqa: E501
    id: Optional[StrictInt] = Field(default=None, description="订单的唯一标识符。")
    user_id: Optional[StrictInt] = Field(default=None, description="创建订单的用户ID。", alias="userID")
    pay_type: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="订单的支付类型，例如 '信用卡', '支付宝', '微信支付' 等。", alias="payType")
    amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="订单的总金额。")
    order_no: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="订单的唯一编号，通常由系统生成。", alias="orderNo")
    trade_no: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="与订单关联的交易编号，通常由支付平台提供。", alias="tradeNo")
    status: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="订单的当前状态，例如 '待支付', '已完成', '已取消' 等。")
    product_type: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="订单中商品的类型分类。", alias="productType")
    product_id: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="订单中商品的唯一标识符。", alias="productID")
    product_name: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="订单中商品的名称。", alias="productName")
    allow_refund: Optional[StrictBool] = Field(default=None, description="指示订单是否允许进行退款操作。", alias="allowRefund")
    allow_refund_until: Optional[datetime] = Field(default=None, description="订单允许进行退款操作的截止时间。", alias="allowRefundUntil")
    tags: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="用于分类或标记订单的标签。")
    remark: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="订单的额外备注信息。")
    description: Optional[StrictStr] = Field(default=None, description="订单的详细描述信息。")
    order_pay_time: Optional[datetime] = Field(default=None, description="订单完成支付的时间。", alias="orderPayTime")
    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", "payType", "amount", "orderNo", "tradeNo", "status", "productType", "productID", "productName", "allowRefund", "allowRefundUntil", "tags", "remark", "description", "orderPayTime", "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 Order 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 pay_type (nullable) is None
        # and model_fields_set contains the field
        if self.pay_type is None and "pay_type" in self.model_fields_set:
            _dict['payType'] = None

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

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

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

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

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

        # set to None if product_name (nullable) is None
        # and model_fields_set contains the field
        if self.product_name is None and "product_name" in self.model_fields_set:
            _dict['productName'] = 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 remark (nullable) is None
        # and model_fields_set contains the field
        if self.remark is None and "remark" in self.model_fields_set:
            _dict['remark'] = 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 Order 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"),
            "payType": obj.get("payType"),
            "amount": obj.get("amount"),
            "orderNo": obj.get("orderNo"),
            "tradeNo": obj.get("tradeNo"),
            "status": obj.get("status"),
            "productType": obj.get("productType"),
            "productID": obj.get("productID"),
            "productName": obj.get("productName"),
            "allowRefund": obj.get("allowRefund"),
            "allowRefundUntil": obj.get("allowRefundUntil"),
            "tags": obj.get("tags"),
            "remark": obj.get("remark"),
            "description": obj.get("description"),
            "orderPayTime": obj.get("orderPayTime"),
            "expireTime": obj.get("expireTime"),
            "createDate": obj.get("createDate"),
            "lastUpdate": obj.get("lastUpdate")
        })
        return _obj


