from pydantic import BaseModel, Field


class LoginRequest(BaseModel):
    username: str = Field(..., description="用户名或手机号")
    password: str = Field(..., description="登录密码")
    captcha_token: str | None = Field(None, description="图形验证码令牌，按现有配置需要时传入")
    remember_me: bool = Field(False, description="是否记住登录")


class SmsLoginRequest(BaseModel):
    phone: str = Field(..., pattern=r"^1[3-9]\d{9}$", description="手机号")
    code: str = Field(..., min_length=4, max_length=8, description="短信验证码")
    remember_me: bool = Field(False, description="是否记住登录")


class RegisterRequest(BaseModel):
    phone: str = Field(..., pattern=r"^1[3-9]\d{9}$", description="手机号，注册成功后 username 默认等于手机号")
    code: str = Field(..., min_length=4, max_length=8, description="注册短信验证码")
    password: str = Field(..., min_length=6, description="新密码，至少6位")

class SetPasswordRequest(BaseModel):
    new_password: str = Field(..., min_length=6, description="新密码，至少6位")


class ChangePasswordRequest(BaseModel):
    old_password: str = Field(..., description="旧密码")
    new_password: str = Field(..., min_length=6, description="新密码，至少6位")


class TokenResponse(BaseModel):
    access_token: str
    token_type: str = "bearer"
