package eventPoint

import (
	"netease_control_center/globals"
	"netease_control_center/interfaces/log"
)

func DeviceDisconEvent(args ...interface{}) {
	if len(args) >= 1 {
		var params map[string]interface{} = map[string]interface{}{
			modelKey: args[0],
		}
		EpRecord(H312, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}

func DeviceConEvent(args ...interface{}) {
	if len(args) >= 1 {
		var params map[string]interface{} = map[string]interface{}{
			modelKey: args[0],
		}
		EpRecord(H311, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}

func PlayPauseEvent(args ...interface{}) {
	if len(args) >= 2 {
		var params map[string]interface{} = map[string]interface{}{
			modelKey: args[0],
			srcIdKey: args[1],
		}
		EpRecord(F141, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}

func MusicStartEvent(args ...interface{}) {
	if len(args) >= 5 {
		var params map[string]interface{} = map[string]interface{}{
			songIdKey:    args[0],
			srcKey:       args[1],
			rspIdKey:     args[2],
			startTypeKey: args[3],
			srcOsKey:     args[4],
		}
		EpRecord(F234, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}

func MusicPauseToPlayEvent(args ...interface{}) {
	if len(args) >= 5 {
		var params map[string]interface{} = map[string]interface{}{
			songIdKey:    args[0],
			srcKey:       args[1],
			rspIdKey:     args[2],
			startTypeKey: args[3],
			srcOsKey:     args[4],
		}
		EpRecord(F236, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}
func MusicEndEvent(args ...interface{}) {
	if len(args) >= 4 {
		var params map[string]interface{} = map[string]interface{}{
			songIdKey: args[0],
			srcKey:    args[1],
			endKey:    args[2],
			srcOsKey:  args[3],
		}
		EpRecord(F235, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}

func SendPlayCmd2IhwPlayer(args ...interface{}) {
	if len(args) >= 4 {
		var params map[string]interface{} = map[string]interface{}{
			audioIdKey:   args[0],
			audioInfoKey: args[1],
			srcOsKey:     args[2],
			"responseid": args[3],
		}
		EpRecord(A235, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}

func AudioStart(args ...interface{}) {
	if len(args) >= 3 {
		var params map[string]interface{} = map[string]interface{}{
			audioIdKey:   args[0],
			audioInfoKey: args[1],
			srcOsKey:     args[2],
		}
		EpRecord(F241, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}

func AudioEnd(args ...interface{}) {
	if len(args) >= 4 {
		var params map[string]interface{} = map[string]interface{}{
			audioIdKey:   args[0],
			audioInfoKey: args[1],
			endKey:       args[2],
			srcOsKey:     args[3],
		}
		EpRecord(F242, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}

//audio error埋点，基本上是timeout出错
func AudioErrorEp(args ...interface{}) {
	if len(args) >= 4 {
		var params map[string]interface{} = map[string]interface{}{
			audioIdKey:   args[0],
			audioInfoKey: args[1],
			endKey:       args[2],
			srcOsKey:     args[3],
			pingAddrKey:  globals.DevNetworkStatus.Ping.Addr,                       //ping地址
			pingDelayKey: globals.DevNetworkStatus.Ping.AvgRtt.Nanoseconds() / 1e6, //ping时延
			"pingTime":   globals.DevNetworkStatus.Time,                            //发送ping时间点
			"rssi":       globals.GetWifiRssi(),                                    //WiFi信号
			"wifi":       globals.CurWifiStatus,                                    //wifi状态
			"internet":   globals.InternetConnect,                                  //联网状态 true为联网， false为断网
		}
		EpRecord(F242, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}

func PrepareTimeout(args ...interface{}) {
	defer func() {
		if err := recover(); err != nil {
			log.Println(log.ErrorLog, err)
		}
	}()
	if len(args) >= 1 {
		var params map[string]interface{} = map[string]interface{}{
			srcIdKey:     args[0],
			pingAddrKey:  globals.DevNetworkStatus.Ping.Addr,                       //ping地址
			pingDelayKey: globals.DevNetworkStatus.Ping.AvgRtt.Nanoseconds() / 1e6, //ping时延
			"pingTime":   globals.DevNetworkStatus.Time,                            //发送ping时间点
			"rssi":       globals.GetWifiRssi(),                                    //WiFi信号
			"wifi":       globals.CurWifiStatus,                                    //wifi状态
			"internet":   globals.InternetConnect,                                  //联网状态 true为联网， false为断网
			rspIdKey:     globals.RspId,
		}

		if len(args) >= 2 {
			params["musicid"] = args[1]
		}
		EpRecord(B251, params)
	} else {
		log.Printf(log.WarningLog, "err params:%+v\n", args)
	}
}
