package globals

import (
	"math"
	"netease_control_center/interfaces/log"
	"netease_control_center/nembd"
	"time"
)

const (
	MaxVolume = 20
	MinVolume = 0

	MinVolPercent = 10
)

func GetVolByPer(volPer int) int {
	return int(math.Ceil(float64(volPer) * MaxVolume / 100))
}

func GetPerByVol(vol int) int {
	return int(float32(vol) / MaxVolume * 100)
}

var (
	Uuid                  string
	AesKey                string
	YxToken               string
	BindUser              string
	CTEI                  string
	OemManufature         int  = 0
	OemManufactureCheckOk bool = false

	SongUrl string
)

var (
	BuildDate    string
	BuildVersion string
	GitTag       *string
	StartTime    time.Time
	Hv           *string
)

const (
	DEFAULT_DEV_NAME = "三音云音箱"
)

var (
	_, _, CPU_SERIAL, CPU_ID, _, _ = nembd.BoardInfo()
)

var (
	ChanWifiParing chan BtWifiParing = make(chan BtWifiParing, 1)

	BTNAME              string        = DEFAULT_DEV_NAME
	APPWIFIPARINGSTAUTS APPInitStatus = APPInitStatus_UNKNOW
	CurBtstatus         BtStatus      = BtStatus{Status: BtEvt_BLE_DISCONNECT}

	IsWifiParingKeyPressed bool = false

	LastActiveTriggerTime = time.Now()

	TtsSel uint8 = XIAOYA_TTS

	HasCheckBirthdayInfo bool = false

	BtNameGetFlag bool = false //lupeng add 20180810
)

const (
	XUNFEI_TTS uint8 = iota
	XIAOYA_TTS
	ROKID_TTS_TEXT
	ROKID_TTS_URL
)

const (
	XUNFEI_TTS_SERVER     = "iflytek"
	XIAOYA_TTS_SERVER     = "orion"
	ROKID_TEXT_TTS_SERVER = "rokidText"
	ROKID_URL_TTS_SERVER  = "rokidUrl"
)

func UpdateActiveTime() {
	LastActiveTriggerTime = time.Now()
}

func IdleTime() time.Duration {
	return time.Now().Sub(LastActiveTriggerTime)
}

var (
	OTA_BEGIN_HOUR        = 2
	OTA_END_HOUR          = 5
	OTA_IDLE_TIME         = 30 * time.Minute
	OTA_NIGHT_FORCE_TIMES = 3
)

func TtsSelCb(e interface{}, cbType CallCbType) {
	if eval, ok := e.(string); ok {
		switch eval {
		case XUNFEI_TTS_SERVER:
			TtsSel = XUNFEI_TTS
		case XIAOYA_TTS_SERVER:
			TtsSel = XIAOYA_TTS
		case ROKID_TEXT_TTS_SERVER:
			TtsSel = ROKID_TTS_TEXT
		case ROKID_URL_TTS_SERVER:
			TtsSel = ROKID_TTS_URL
		default:
			TtsSel = XIAOYA_TTS
		}
		log.Printf(log.WarningLog, "server:%+v  ttssel:%+v\n", TtsType.GetCfgListStr(), TtsSel)
	} else {
		log.Println(log.ErrorLog, "err cfglist type")
	}

}
