package middleware

import (
	"game-driver/internal/schema"
	"game-driver/leaf"
	"game-driver/pkg/tts"
)

// SoundStart 开始词播报
func SoundStart() leaf.HandlerFunc {
	return func(c *leaf.Context) {
		pm := leaf.Value[*schema.PlayModal](c, PayloadJSONKey)
		tts.DefaultTTS.Sound(pm.TTS.Start)

		defer func() {
			switch leaf.Value[leaf.EndType](c, leaf.EndKey) {
			case leaf.End:
				tts.DefaultTTS.Sound(pm.TTS.End)
			case leaf.EndTimeout:
				tts.DefaultTTS.Sound(pm.TTS.Timeout)
			case leaf.EndStop:
				tts.DefaultTTS.Sound(pm.TTS.Stop)
			}
		}()

		c.Next()
	}
}
