from pydantic import BaseModel
from typing import Optional
from datetime import datetime

# VM 정보 응답
class VMInfo(BaseModel):
    vm_id: int
    node: str
    name: str
    status: str
    ip_address: Optional[str] = None
    cpus: int
    memory: int  # MB
    memory_usage: Optional[int] = None
    cpu_usage: Optional[float] = None
    uptime: Optional[int] = None
    
    # 접근 권한 정보
    can_start: bool = True
    can_stop: bool = True
    can_reboot: bool = True
    can_connect: bool = True
    
    # RDP 연결 정보 (VMAccess에서 가져옴)
    rdp_username: Optional[str] = None
    rdp_password: Optional[str] = None
    rdp_port: int = 3389

# VM 목록 응답
class VMListResponse(BaseModel):
    total: int
    vms: list[VMInfo]

# VM 상세 정보
class VMDetail(VMInfo):
    rdp_port: int = 3389
    rdp_username: Optional[str] = None
    has_guest_agent: bool = False
    
    class Config:
        from_attributes = True

# VM 제어 요청
class VMControlRequest(BaseModel):
    action: str  # "start", "stop", "reboot"

# VM 제어 응답
class VMControlResponse(BaseModel):
    success: bool
    message: str
    vm_id: int
    action: str
