# 联软LV7000数据模型
"""
定义联软API返回数据的Pydantic模型。

核心模型：
- TerminalBasicInfo：终端基本信息（queryDevByParams返回）
- TerminalAllInfo：终端详细信息（getDevAllInfo返回，极详细）
- UserInfo：用户信息（getUserInfoByAccount返回）
- OrgInfo：组织架构信息（getAllOrgInfo返回）
- OnlineStatus：终端在线状态（existOnlineUser返回）
"""

from typing import Optional
from pydantic import BaseModel, Field


# ==========================================================================
# 终端基本信息（queryDevByParams返回）
# ==========================================================================

class TerminalBasicInfo(BaseModel):
    """终端基本信息 — 最核心的映射数据源。
    
    ⭐ strusername + struserdes 字段直接提供员工账号→终端映射！
    这是联软相比火绒最大的优势。
    """
    # 终端标识
    strdevname: str = Field(default="", description="计算机名")
    strdevip: str = Field(default="", description="IP地址")
    strmac: str = Field(default="", description="MAC地址")
    
    # ⭐ 员工映射字段（核心价值）
    strusername: str = Field(default="", description="使用该终端的用户账号（映射金钥匙）")
    struserdes: str = Field(default="", description="用户姓名/描述")
    
    # 组织信息
    strdeptname: str = Field(default="", description="所属部门名")
    
    # 状态
    istatus: str = Field(default="", description="终端状态（1=在线/0=离线）")
    
    # 网络
    strswitchname: str = Field(default="", description="接入交换机名")
    strifname: str = Field(default="", description="交换机接口名")
    
    # 联系方式
    strmail: str = Field(default="", description="用户邮箱")
    strphone: str = Field(default="", description="用户电话")
    
    # 其他
    strdomain: str = Field(default="", description="Windows域")
    strdevtype: str = Field(default="", description="设备类型")


# ==========================================================================
# 终端详细信息（getDevAllInfo返回）
# ==========================================================================

class HardwareInfo(BaseModel):
    """硬件组件信息"""
    name: str = Field(default="", description="名称")
    model: str = Field(default="", description="型号")
    vendor: str = Field(default="", description="厂商")
    capacity: str = Field(default="", description="容量")
    serial: str = Field(default="", description="序列号")


class LogicalDiskInfo(BaseModel):
    """逻辑磁盘信息（含使用率，判断磁盘满）"""
    name: str = Field(default="", description="卷标")
    file_system: str = Field(default="", description="文件系统")
    total_size: str = Field(default="", description="总量")
    free_space: str = Field(default="", description="可用空间")
    usage_percent: str = Field(default="", description="使用率")


class NetworkCardInfo(BaseModel):
    """网卡信息"""
    name: str = Field(default="", description="名称")
    is_wireless: str = Field(default="", description="是否无线")
    vendor: str = Field(default="", description="厂商")
    mac: str = Field(default="", description="MAC地址")


class DisplayInfo(BaseModel):
    """显示器信息（多屏配置排查）"""
    vendor: str = Field(default="", description="厂商")
    model: str = Field(default="", description="型号")
    serial: str = Field(default="", description="序列号")
    size: str = Field(default="", description="尺寸")


class TerminalAllInfo(BaseModel):
    """终端详细信息 — 极其详细，比火绒_info2更丰富。
    
    包含：设备基础+硬件+软件+资产+网络配置。
    特别是逻辑磁盘使用率和显示器信息，是火绒没有的。
    """
    # 设备基础
    strdevname: str = Field(default="", description="计算机名")
    strip1: str = Field(default="", description="IP地址")
    strmac: str = Field(default="", description="MAC地址")
    strnatip: str = Field(default="", description="NAT IP")
    macverdor: str = Field(default="", description="MAC厂商")
    strdevtype: str = Field(default="", description="设备类型")
    
    # 组织+用户
    strdeptname: str = Field(default="", description="所属部门")
    strusername: str = Field(default="", description="用户账号⭐")
    struserdes: str = Field(default="", description="用户姓名⭐")
    
    # 时间
    dtdevuptime: str = Field(default="", description="最近上线时间")
    dtdevdowntime: str = Field(default="", description="最近下线时间")
    dtdevfirstfoundtime: str = Field(default="", description="首次发现时间")
    
    # 系统
    stros: str = Field(default="", description="操作系统")
    strdomain: str = Field(default="", description="Windows域")
    strserialnumber: str = Field(default="", description="序列号")
    strmainboardtype: str = Field(default="", description="主板型号")
    
    # 客户端详情
    strverofuaagent: str = Field(default="", description="安全助手版本")
    istatus: str = Field(default="", description="在线状态")
    devassetno: str = Field(default="", description="设备资产号")
    devgroup: str = Field(default="", description="设备所属设备组")
    
    # 硬件详情（列表）
    mainboard: list[HardwareInfo] = Field(default_factory=list, description="主板信息")
    cpu: list[HardwareInfo] = Field(default_factory=list, description="CPU信息")
    memory: list[HardwareInfo] = Field(default_factory=list, description="内存信息")
    hard_disk: list[HardwareInfo] = Field(default_factory=list, description="硬盘信息")
    logical_disk: list[LogicalDiskInfo] = Field(default_factory=list, description="逻辑磁盘")
    graphics_card: list[HardwareInfo] = Field(default_factory=list, description="显卡信息")
    network_card: list[NetworkCardInfo] = Field(default_factory=list, description="网卡信息")
    display: list[DisplayInfo] = Field(default_factory=list, description="显示器信息")


# ==========================================================================
# 用户信息（getUserInfoByAccount返回）
# ==========================================================================

class UserInfo(BaseModel):
    """用户信息"""
    deptid: str = Field(default="", description="部门ID")
    userid: str = Field(default="", description="用户ID")
    useraccount: str = Field(default="", description="用户账号")
    username: str = Field(default="", description="用户姓名")


# ==========================================================================
# 组织架构信息（getAllOrgInfo返回）
# ==========================================================================

class OrgDeptInfo(BaseModel):
    """部门信息"""
    deptid: str = Field(default="", description="部门ID")
    deptname: str = Field(default="", description="部门名称")
    parentid: str = Field(default="", description="父部门ID")
    users: list[UserInfo] = Field(default_factory=list, description="部门下用户列表")


# ==========================================================================
# 终端在线状态（existOnlineUser返回）
# ==========================================================================

class OnlineStatus(BaseModel):
    """终端在线状态"""
    username: str = Field(default="", description="用户名")
    ip: str = Field(default="", description="IP地址")
    is_online: bool = Field(default=False, description="是否在线")


# ==========================================================================
# 软件信息（querysoftwarebydev返回）
# ==========================================================================

class SoftwareInfo(BaseModel):
    """软件安装信息"""
    name: str = Field(default="", description="软件名称")
    version: str = Field(default="", description="版本")
    vendor: str = Field(default="", description="厂商")
    install_date: str = Field(default="", description="安装日期")


class TerminalSoftwareInfo(BaseModel):
    """终端安装软件信息"""
    strdevname: str = Field(default="", description="计算机名")
    strdevip: str = Field(default="", description="IP地址")
    strmac: str = Field(default="", description="MAC地址")
    strusername: str = Field(default="", description="用户账号")
    softwares: list[SoftwareInfo] = Field(default_factory=list, description="软件列表")
