"""通用响应模型

提供常见的响应包装类，如 Result[T]、PageInfo 等。
"""

from typing import Generic, TypeVar

from pydantic import BaseModel, Field

T = TypeVar("T")


# ========== AUTO-GENERATED START ==========
# 此区域由脚手架自动生成，重新生成时会被更新


class Result(BaseModel, Generic[T]):
    """通用响应包装

    常见格式:
        {
          "code": 200,
          "message": "success",
          "data": { ... }
        }

    使用示例:
        >>> class UserResponse(BaseModel):
        ...     id: int
        ...     name: str
        >>>
        >>> response_data = {"code": 200, "message": "success", "data": {"id": 1, "name": "Alice"}}
        >>> result = Result[UserResponse](**response_data)
        >>> print(result.data.name)  # Alice
    """

    code: int = Field(..., description="业务状态码")
    message: str = Field(..., description="响应消息")
    data: T | None = Field(None, description="响应数据")


class PageInfo(BaseModel, Generic[T]):
    """分页响应

    常见格式:
        {
          "total": 100,
          "current": 1,
          "size": 20,
          "records": [...]
        }
    """

    total: int = Field(..., description="总记录数")
    current: int = Field(default=1, description="当前页码")
    size: int = Field(default=20, description="每页大小")
    records: list[T] = Field(default_factory=list, description="记录列表")


# ========== AUTO-GENERATED END ==========


# ========== USER EXTENSIONS ==========
# 在此区域添加自定义代码，重新生成时会保留


__all__ = ["Result", "PageInfo"]
