package standby

import (
	"context"
	"fmt"
	"game-driver/config/game"
	"game-driver/internal/schema"
	"game-driver/pkg/oscx"
	"go.uber.org/zap"
)

func LaserShow(item schema.WaitItemModel) func(c context.Context) error {
	cfg := (game.C).(game.LaserConfig)

	return func(c context.Context) error {
		zap.S().Infoln("开始播放大型激光秀")

		o := oscx.New(cfg.Host, cfg.Port)
		err := o.EnableLaserOutput()
		if err != nil {
			return fmt.Errorf("激光打开异常: %w", err)
		} else {
			defer zap.S().Infoln("大型激光秀播放结束:", item.Data)
			defer o.DisableLaserOutput()

			err = o.StartCue(item.Data)
			if err != nil {
				return fmt.Errorf("播放大型激光节目异常: %w", err)
			}
		}

		<-c.Done()
		return nil
	}
}
