import { prisma } from "./db/prisma.js";
import { logger } from "./core/logger.js";
import { registerCommands } from "./discord/register-commands.js";
import { createBotClient } from "./discord/client.js";

async function bootstrap() {
  await prisma.$connect();
  await registerCommands();
  const bot = createBotClient();
  await bot.start();
}

bootstrap().catch(async (error) => {
  logger.error({ error }, "Fatal bootstrap error");
  try {
    await prisma.$disconnect();
  } catch {
    // noop
  }
  process.exit(1);
});

process.on("SIGINT", async () => {
  await prisma.$disconnect();
  process.exit(0);
});
