package main

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"
	"velox-bot/internal/bot"
	"velox-bot/internal/commands"
	"velox-bot/internal/config"
	"velox-bot/internal/db"
	"velox-bot/internal/db/repos/levelrepo"
	"velox-bot/internal/db/repos/settingsrepo"
	"velox-bot/internal/db/services"
	"velox-bot/internal/db/services/level"
	"velox-bot/internal/db/services/levelsettings"
)

func main() {
	config, err := config.LoadConfig()
	if err != nil {
		log.Fatalf("Error loading config: %v", err)
		return
	}

	db, err := db.NewDB(config)
	if err != nil {
		log.Fatalf("Error creating database: %v", err)
		return
	}
	defer db.Close()

	levelRepo := levelrepo.NewRepo(db)
	settingsRepo := settingsrepo.NewRepo(db)
	levelService := level.New(levelRepo, settingsRepo)
	levelSettingsService := levelsettings.New(settingsRepo)
	services := services.NewServices(levelService, levelSettingsService)

	bot, err := bot.NewBot(config.BotToken, config.AppID, config.GuildID, commands.AllCommands, services)
	if err != nil {
		log.Fatalf("Error creating bot: %v", err)
		return
	}

	err = bot.Start()
	if err != nil {
		log.Fatalf("Error starting bot: %v", err)
	}

	defer bot.Close()

	fmt.Println("Bot is running...")

	sc := make(chan os.Signal, 1)
	signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
	<-sc
}
