package status

import (
	logger2 "agent-go/logger"
	"fmt"
	"time"
)

var log = logger2.Log

type StatusMessage struct {
	/**
	  * which kind of status should be return
		 "PING";
	   * METRIC => short time message
	   * ALL => all agent status message
	  * */
	StatusType        string `json:"statusType,omitempty"`
	MetricRepeatCount int    `json:"metricRepeatCount,omitempty"`
	metricRepeatPinch int    `json:"metricRepeatPinch,omitempty"`
}

type AgentStatus struct {
	CPUStatus     *CPUStatus
	MemoryStatus  *MemoryStatus
	NetworkStatus *NetworkStatus
	DiskStatus    *DiskStatus
}

func ConvertToFormat(eventData float64) string {
	duration := time.Duration(eventData) * time.Second

	fmt.Println(duration)

	hours := int(duration.Hours())
	minutes := int(duration.Minutes()) % 60
	seconds := int(duration.Seconds()) % 60
	milliseconds := duration.Milliseconds() % 1000
	return fmt.Sprintf("%02d:%02d:%02d,%03d", hours, minutes, seconds, milliseconds)
}

func Ping() string {
	return "PONG"
}

// todo change to go model
func ReportAppStatus() *AgentStatus {

	cpuStatus, cpuerr := GetCPUStatus()
	memoryStatus, memerr := GetMemoryStatus()
	networkStatus, neterr := GetNetworkStatus()
	if cpuerr != nil || memerr != nil || neterr != nil {
		log.ErrorF("获取Agent的状态出现错误！ 请检查")
		return nil
	}
	diskStatus := GetDiskStatus()
	return &AgentStatus{
		CPUStatus:     cpuStatus,
		MemoryStatus:  memoryStatus,
		NetworkStatus: networkStatus,
		DiskStatus:    diskStatus,
	}

}
