package schedule

import (
	"netease_control_center/globals"
	"netease_control_center/interfaces/vui"
	"netease_control_center/modules/hardware/mcu_leds/atservice"
	"sync"
	"time"
)

type DirectLed struct {
	EffectId     atservice.GUIDE_EFFECT_ID
	Action       atservice.GUIDE_ACTION
	StartLampNum uint8
	Data         []byte
}

type TtsPlayerArg struct {
	StopReason NoticeStopReason
}

type NoticePlayerParams struct {
	Tts               string
	Uuid              string
	SrcType           globals.AdSrcType
	Level             globals.TtsLevel
	NeedRepeat        bool
	Keep              bool
	IconIn            vui.IconLedDesc
	IconOut           vui.IconLedDesc
	LedOn             DirectLed
	LedOff            DirectLed
	SpecialCmd        string
	SpecialFunc       func(arg TtsPlayerArg)
	BeforeSpecialFunc func()
	BeforeExecFunc    func()

	NextNode interface{} // *NoticePlayerParams
}

type ttsRepeat struct {
	NoticePlayerParams
	TimePlay time.Time

	HasSetTtsInfo bool
}

var (
	ttsRepeatInfo ttsRepeat = ttsRepeat{HasSetTtsInfo: false}

	rwLock sync.RWMutex
)

func lock() {
	rwLock.Lock()
}

func unLock() {
	rwLock.Unlock()
}

func rLock() {
	rwLock.RLock()
}

func rUnLock() {
	rwLock.RUnlock()
}

func GetTtsRepeatInfo() ttsRepeat {
	rLock()
	defer rUnLock()

	return ttsRepeatInfo
}

func SetTtsRepeatInfo(ttsInfo NoticePlayerParams) {
	lock()
	defer unLock()

	ttsRepeatInfo.NoticePlayerParams = ttsInfo
	ttsRepeatInfo.HasSetTtsInfo = true
	ttsRepeatInfo.TimePlay = time.Now()

	//log.Printf(log.WarningLog, "ttsRepeatInfo:%+v\n", ttsRepeatInfo)
}

func ClearTtsRepeatInfo() {
	lock()
	defer unLock()

	ttsRepeatInfo.HasSetTtsInfo = false
}
func GetNoticePlayerParams(tts string, uuid string, srcType globals.AdSrcType,
	level globals.TtsLevel, needRepeat bool, keep bool) NoticePlayerParams {
	var tmp NoticePlayerParams
	tmp.Tts = tts
	tmp.Uuid = uuid
	tmp.SrcType = srcType
	tmp.Level = level
	tmp.NeedRepeat = needRepeat
	tmp.Keep = keep
	// todo : others aprams

	return tmp
}
