package main

import (
	"log"

	"go-helper/internal/bot"
	"go-helper/internal/chatgpt"
	"go-helper/internal/config"
	"go-helper/internal/database"
	"go-helper/internal/scheduler"
)

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)

	// Load configuration.
	cfg := config.Load()

	// Initialise database.
	db := database.New(cfg.DatabaseURL)
	defer db.Close()

	// Create ChatGPT API client.
	client := chatgpt.NewClient(cfg.ProxyURL)

	// Create OAuth manager (no server needed, uses URL-paste flow).
	oauth := chatgpt.NewOAuthManager(client)

	// Start scheduled token checker.
	scheduler.StartTokenChecker(db, client, cfg.TokenCheckInterval)

	// Start Telegram bot (blocking).
	log.Println("[Main] 启动 Telegram Bot...")
	bot.Start(db, cfg, client, oauth)
}
