package utility

import (
	"fmt"
	tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
	"log"
)

// G2A 상품수집 결과
func SendMessageToG2AProduct(msg string) {
	SendMessage("6236017150:AAGsCufu7QT6-MdEUXdda9_frczPwnGXuL0", 650107127, msg)
}

// G2A 상품주문 결과
func SendMessageToG2AOrder(msg string) {
	SendMessage("5816574764:AAETUt5eIbdORTkKEpE6DkdBG4q18jycUQ4", 650107127, msg)
}

// G2A 오류 내역
func SendMessageToG2AError(msg string) {
	SendMessage("6249107543:AAFJHE3dZl8I0JFgMpyLMUoUS4pUiRhbIc0", 650107127, msg)
}

func SendMessage(token string, chatID int64, msg string) {
	defer func() {
		if e := recover(); e != nil {
			fmt.Printf("Telegram recover error: %s\n", e)
		}
	}()

	bot, err := tgbotapi.NewBotAPI(token)
	if err != nil {
		log.Panic(err)
	}

	bot.Debug = true

	chat, _ := bot.GetChat(tgbotapi.ChatInfoConfig{
		tgbotapi.ChatConfig{
			ChatID: chatID,
		},
	})

	bot.Send(tgbotapi.NewMessage(chat.ID, msg))
}
