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

from core.pydantic import BaseResponse
from schemas.permission import PermissionResponse
from schemas.role import RoleResponse


class UserRoleRequest(BaseModel):
    role_ids: List[int] = Field(..., description="角色ID列表")


class UserRoleResponse(BaseResponse):
    id: int = Field(..., description="用户角色关联ID")
    user_id: int = Field(..., description="用户ID")
    role: RoleResponse = Field(..., description="角色信息")
    is_active: bool = Field(..., description="是否启用")


class UserWithRolesResponse(BaseModel):
    id: int = Field(..., description="用户ID")
    username: str = Field(..., description="用户名")
    nickname: Optional[str] = Field(None, description="昵称")
    is_active: bool = Field(..., description="是否激活")
    is_staff: bool = Field(..., description="是否在职")
    is_superuser: bool = Field(..., description="是否超级用户")
    roles: List[RoleResponse] = Field(default=[], description="用户角色")
    permissions: List[PermissionResponse] = Field(default=[], description="用户权限")

    class Config:
        from_attributes = True
