import { AuroraClient } from "@/lib/BotClient";
import { env } from "@lib/env";

import { WebServer } from "@/web/server";

// Load commands & events
await AuroraClient.loadCommands();
await AuroraClient.loadEvents();
await AuroraClient.deployCommands();

WebServer.start();

// login with the token from .env
if (!env.DISCORD_BOT_TOKEN) {
    throw new Error("❌ DISCORD_BOT_TOKEN is not set in environment variables.");
}
AuroraClient.login(env.DISCORD_BOT_TOKEN);

// Handle graceful shutdown
const shutdownHandler = () => {
    WebServer.stop();
    AuroraClient.shutdown();
};

process.on("SIGINT", shutdownHandler);
process.on("SIGTERM", shutdownHandler);