package main

import (
	"bot/src/controllers"
	"bot/src/handlers"
	"bot/src/models"
	"log"
	"os"
	"time"

	tele "gopkg.in/telebot.v4"
	"gopkg.in/yaml.v3"
)

func config() models.Config {
	file, err := os.Open("cfg.yml")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	// unmarshal the YAML data into a struct
	var config models.Config
	err = yaml.NewDecoder(file).Decode(&config)
	if err != nil {
		log.Fatal(err)
	}

	return config
}
func main() {
	cfg := config()
	pref := tele.Settings{
		Token:  cfg.Token,
		Poller: &tele.LongPoller{Timeout: 10 * time.Second},
	}

	b, err := tele.NewBot(pref)
	if err != nil {
		log.Fatal(err)
		return
	}

	dc := controllers.NewDB(cfg)
	dataHandler := handlers.NewHandlers(dc)
	duelController := controllers.NewDuel(b, dc)

	b.Handle("/dick", dataHandler.Dick)
	b.Handle("/top_dick", dataHandler.TopDick)

	b.Handle("/duel", duelController.StartMatch)
	b.Handle("/accept", duelController.AcceptMatch)

	b.Start()
}
