package tg

import (
	"time"

	tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
	"github.com/sirupsen/logrus"
	"github.com/spf13/viper"
)

func StartGameTimer() {
	waitSecond := viper.GetInt("wait_second")
	for {
		logrus.Info("run...")
		sendGameInfo()
		<-time.After(time.Duration(waitSecond) * time.Second)
	}
}

func sendGameInfo() {
	chatID := viper.GetInt64("chat_id")
	gifMsg := tgbotapi.GameConfig{
		BaseChat: tgbotapi.BaseChat{
			ChatID:      chatID,
			ReplyMarkup: GetGameReplyMarkup(),
		},
		GameShortName: "qznn",
	}

	event2.MustFire(EventSendMsg, event2.M{
		"msg": gifMsg,
	})
}

func GetGameReplyMarkup() tgbotapi.InlineKeyboardMarkup {
	gameBtn := tgbotapi.NewInlineKeyboardButtonData("🎮进入游戏", "")
	gameBtn.CallbackGame = &tgbotapi.CallbackGame{}
	gameBtn.CallbackData = nil

	return tgbotapi.NewInlineKeyboardMarkup(
		tgbotapi.NewInlineKeyboardRow(
			gameBtn,
		),
	)
}
