from pydantic import BaseModel, EmailStr
from typing import Optional, List
from datetime import datetime

# 사용자 관리
class UserCreate(BaseModel):
    username: str
    email: EmailStr
    password: str
    full_name: Optional[str] = None
    role: str = "user"  # admin or user

class UserUpdate(BaseModel):
    email: Optional[EmailStr] = None
    password: Optional[str] = None
    full_name: Optional[str] = None
    role: Optional[str] = None
    is_active: Optional[bool] = None

class UserInfo(BaseModel):
    id: int
    username: str
    email: str
    full_name: Optional[str]
    role: str
    is_active: bool
    created_at: datetime
    last_login: Optional[datetime]

class UserListResponse(BaseModel):
    total: int
    users: List[UserInfo]

# VM 접근 권한 관리
class VMAccessCreate(BaseModel):
    user_id: int
    vm_id: int
    node: str
    static_ip: Optional[str] = None
    rdp_username: Optional[str] = None
    rdp_password: Optional[str] = None
    rdp_port: int = 3389

class VMAccessUpdate(BaseModel):
    static_ip: Optional[str] = None
    rdp_username: Optional[str] = None
    rdp_password: Optional[str] = None
    rdp_port: Optional[int] = None
    is_active: Optional[bool] = None

class VMAccessInfo(BaseModel):
    id: int
    user_id: int
    username: str  # 조인해서 가져옴
    vm_id: int
    node: str
    vm_name: Optional[str]
    static_ip: Optional[str]
    rdp_username: Optional[str]
    rdp_port: int
    is_active: bool
    created_at: datetime

class VMAccessListResponse(BaseModel):
    total: int
    accesses: List[VMAccessInfo]

# 공통 응답
class AdminResponse(BaseModel):
    success: bool
    message: str
