from pydantic import BaseModel, Field, ConfigDict
from typing import Optional


class UserRequest(BaseModel):
    username: str
    password: str

class UserInfoBase(BaseModel):
    """
    ⽤户信息基础数据模型
    """
    nickname: Optional[str] = Field(None, max_length=50, description="昵称")
    avatar: Optional[str] = Field(None, max_length=255, description="头像URL")
    gender: Optional[str] = Field(None, max_length=10, description="性别")
    bio: Optional[str] = Field(None, max_length=500, description="个⼈简介")


# user_info 对应的类: 基础类 + Info 类(id、用户名)
class UserInfoResponse(UserInfoBase):
    id: int
    username: str
    model_config = ConfigDict(
        from_attributes= True     # 模型类属性(允许从 ORM 对象属性中取值)
    )


# data 数据类型
class UserAuthResponse(BaseModel):
    token: str
    user_info: UserInfoResponse = Field(..., alias = "userInfo")

    # 模型类配置
    model_config = ConfigDict(
        populate_by_name=True,   # 字段名与属性名一致
        from_attributes= True     # 模型类属性(允许从 ORM 对象属性中取值)
    )

# 更新用户信息的模型类
class UserUpdateRequest(BaseModel):
    nickname: str = None,
    avatar: str = None,
    gender: str = None,
    bio: str = None
    phone: str = None



# 修改用户密码
class UserChangePasswordRequest(BaseModel):
    old_password: str = Field(..., alias = "oldPassword", description="旧密码")
    new_password: str = Field(..., min_length = 6, alias = "newPassword", description="新密码")