import 'dotenv/config';
import { env } from './env.js';
import { createBot } from './bot.js';
import { logger } from './utils/logger.js';

const bot = createBot(env);

bot.launch().catch((err) => {
  logger.error('Failed to launch bot', { error: String(err) });
  process.exit(1);
});

logger.info('Hetzi bot started', {
  allowedChats: env.TELEGRAM_ALLOWED_CHAT_IDS,
  repoPath: env.HETZI_REPO_PATH,
  claudeBin: env.CLAUDE_BIN,
});

process.once('SIGINT', () => {
  logger.info('Shutting down (SIGINT)');
  bot.stop('SIGINT');
});

process.once('SIGTERM', () => {
  logger.info('Shutting down (SIGTERM)');
  bot.stop('SIGTERM');
});
