"""Agent 上报数据 Schema"""

from typing import List, Optional

from pydantic import Field
from sqlmodel import SQLModel


class MetricsIn(SQLModel):
    cpu_pct: Optional[float] = None
    mem_pct: Optional[float] = None
    disk_pct: Optional[float] = None
    net_in_mb: Optional[float] = None
    net_out_mb: Optional[float] = None
    load_1m: Optional[float] = None
    uptime_sec: Optional[int] = None


class ServerInfoIn(SQLModel):
    hostname: Optional[str] = None
    os: Optional[str] = None
    kernel: Optional[str] = None
    cpu_cores: Optional[int] = None
    mem_total_gb: Optional[float] = None
    disk_total_gb: Optional[float] = None
    public_ip: Optional[str] = None
    tailscale_ip: Optional[str] = None
    status: Optional[str] = "online"


class SecurityCheckIn(SQLModel):
    check_item: str
    status: str = "unknown"  # pass/warn/fail/unknown
    detail: Optional[str] = None
    suggestion: Optional[str] = None


class AgentReport(SQLModel):
    """Agent 单次上报的完整数据包"""

    asset_id: int
    metrics: Optional[MetricsIn] = None
    server_info: Optional[ServerInfoIn] = None
    # 限制单次上报的检查项数量，防止恶意/异常 Agent 发送超大数组撑爆内存
    security: Optional[List[SecurityCheckIn]] = Field(default=None, max_length=100)
