"""
认证相关 Schema
===============
"""

from pydantic import BaseModel, Field

from app.schemas.user import UserInfo


class MobileLoginRequest(BaseModel):
    """手机号验证码登录请求"""

    mobile: str = Field(..., description="手机号", min_length=11, max_length=20)
    code: str = Field(..., description="短信验证码", min_length=4, max_length=10)
    device_id: str = Field(..., description="设备唯一标识")
    device_name: str | None = Field(None, description="设备名称")
    os_info: str | None = Field(None, description="操作系统信息")
    app_version: str | None = Field(None, description="应用版本号")


class SendSmsCodeRequest(BaseModel):
    """发送短信验证码请求"""

    mobile: str = Field(..., description="手机号", min_length=11, max_length=20)


class RefreshTokenRequest(BaseModel):
    """刷新 Token 请求"""

    refresh_token: str = Field(..., description="Refresh Token")


class TokenResponse(BaseModel):
    """Token 响应（登录/刷新共用）"""

    access_token: str = Field(..., description="Access Token（30 分钟有效）")
    refresh_token: str = Field(..., description="Refresh Token（30 天有效）")
    user: UserInfo = Field(..., description="用户信息")


class TokenPayload(BaseModel):
    """Token 载荷"""

    sub: str | None = Field(None, description="用户 ID")
    type: str | None = Field(None, description="Token 类型：access / refresh")
    jti: str | None = Field(None, description="JWT 唯一标识（Refresh Token 用）")
    exp: int | None = Field(None, description="过期时间戳")
