# _*_ coding : UTF-8 _*_
# @Time : 2025/02/04 15:26
# @UpdateTime : 2025/02/04 15:26
# @Author : sonder
# @File : server.py
# @Software : PyCharm
# @Comment : 本程序
from typing import Optional, List

from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel

from schemas.common import BaseResponse


class CpuInfo(BaseModel):
    """
    CPU信息
    """
    model_config = ConfigDict(alias_generator=to_camel)

    cpu_num: Optional[int] = Field(default=None, description='核心数')
    used: Optional[float] = Field(default=None, description='CPU用户使用率')
    sys: Optional[float] = Field(default=None, description='CPU系统使用率')
    free: Optional[float] = Field(default=None, description='CPU当前空闲率')


class MemoryInfo(BaseModel):
    """
    内存信息
    """
    model_config = ConfigDict(alias_generator=to_camel)

    total: Optional[str] = Field(default=None, description='内存总量')
    used: Optional[str] = Field(default=None, description='已用内存')
    free: Optional[str] = Field(default=None, description='剩余内存')
    usage: Optional[float] = Field(default=None, description='使用率')


class SystemInfo(BaseModel):
    """
    系统信息
    """
    model_config = ConfigDict(alias_generator=to_camel)

    computer_ip: Optional[str] = Field(default=None, description='服务器IP')
    computer_name: Optional[str] = Field(default=None, description='服务器名称')
    os_arch: Optional[str] = Field(default=None, description='系统架构')
    os_name: Optional[str] = Field(default=None, description='操作系统')
    user_dir: Optional[str] = Field(default=None, description='项目路径')


class PythonInfo(MemoryInfo):
    """
    Python信息
    """
    model_config = ConfigDict(alias_generator=to_camel)

    name: Optional[str] = Field(default=None, description='Python名称')
    version: Optional[str] = Field(default=None, description='Python版本')
    start_time: Optional[str] = Field(default=None, description='启动时间')
    run_time: Optional[str] = Field(default=None, description='运行时长')
    home: Optional[str] = Field(default=None, description='安装路径')


class SystemFiles(BaseModel):
    """
    系统磁盘信息
    """
    model_config = ConfigDict(alias_generator=to_camel)

    dir_name: Optional[str] = Field(default=None, description='盘符路径')
    sys_type_name: Optional[str] = Field(default=None, description='盘符类型')
    type_name: Optional[str] = Field(default=None, description='文件类型')
    total: Optional[str] = Field(default=None, description='总大小')
    used: Optional[str] = Field(default=None, description='已经使用量')
    free: Optional[str] = Field(default=None, description='剩余大小')
    usage: Optional[str] = Field(default=None, description='资源的使用率')


class GetSystemInfoResult(BaseModel):
    """
    获取系统信息结果
    """
    model_config = ConfigDict(alias_generator=to_camel)

    cpu: Optional[CpuInfo] = Field(description='CPU相关信息')
    python: Optional[PythonInfo] = Field(description='Python相关信息')
    memory: Optional[MemoryInfo] = Field(description='內存相关信息')
    system: Optional[SystemInfo] = Field(description='服务器相关信息')
    system_files: Optional[List[SystemFiles]] = Field(description='磁盘相关信息')


class GetServerInfoResponse(BaseResponse):
    """
    获取服务器信息响应
    """
    data: GetSystemInfoResult = Field(default={}, description="服务器信息查询结果")
