package protocol

type CpuInfo struct {
	Cpus      int     `json:"cpus"`
	Cores     int     `json:"cores"`
	ModelName string  `json:"model"`
	Percent   float64 `json:"percent"` //状态信息
}

type MemInfo struct {
	Total     uint64  `json:"total"`
	Available uint64  `json:"available"`
	Used      uint64  `json:"used"`
	Percent   float64 `json:"percent"`
}

type DiskInfo struct {
	Device     string  `json:"device"`
	Mountpoint string  `json:"mountpoint"`
	Fstype     string  `json:"fstype"`
	Path       string  `json:"path"`
	Total      uint64  `json:"total"`
	Free       uint64  `json:"free"`
	Used       uint64  `json:"used"`
	Percent    float64 `json:"percent"`
}

type ProcessInfo struct {
	Pid  int32   `json:"pid"`
	Name string  `json:"name"`
	Cpu  float64 `json:"cpu"`
	Mem  float64 `json:"mem"`
}

type LcInterfaces struct {
	Name         string `json:"name"` // e.g., "en0", "lo0", "eth0.100"
	HardwareAddr string `json:"mac"`
	Addr         string `json:"addr"`
	Sent         uint64 `json:"sent"`        // number of bytes sent
	Recv         uint64 `json:"recv"`        // number of bytes received
	PacketsSent  uint64 `json:"packetssent"` // number of packets sent
	PacketsRecv  uint64 `json:"packetsrecv"` // number of packets received
}

type ConnectionInfo struct {
	Type   uint32 `json:"type"`
	Laddr  string `json:"localaddr"`  //ip:port
	Raddr  string `json:"remoteaddr"` //ip:port
	Status string `json:"status"`     //连接状态
	Pid    int32  `json:"pid"`        //进程ID
}

type AppInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type SysInfo struct {
	Appinfo   AppInfo          `json:"appinfo"`
	Cpuinfo   *CpuInfo         `json:"cpuinfo,omitempty"`
	Meminfo   *MemInfo         `json:"meminfo,omitempty"`
	Diskinfos []DiskInfo       `json:"diskinfo,omitempty"`
	Ifs       []LcInterfaces   `json:"ifs,omitempty"`
	Pis       []ProcessInfo    `json:"pis,omitempty"`
	TcpListen []ConnectionInfo `json:"tcplisten,omitempty"`
	TcpConn   []ConnectionInfo `json:"tcpconn,omitempty"`
	Udp       []ConnectionInfo `json:"udp,omitempty"`
}

type Pack_SysInfo struct {
	Header
	Data SysInfo `json:"data"`
}

func (o *Pack_SysInfo) EnCode(id, gid string, seq uint64, data SysInfo) (string, error) {
	o.Header.SetHeaderData(id, gid, seq)
	o.Data = data
	return json.MarshalToString(o)
}
func (o *Pack_SysInfo) DeCode(message string) error {
	return json.UnmarshalFromString(message, o)
}
