import { mkdirSync } from 'node:fs';
import { DATA_PATH, ensureItemDirs } from './data-path';
import { ensureToolLoader } from './ensure-tool-loader';
// Queue is now owned by the sidecar process
import { startDiscordBotIfConfigured } from './channels/discord/bot';
import { startTelegramBotIfConfigured } from './channels/telegram/bot';
import { startWhatsAppBotIfConfigured } from './channels/whatsapp/bot';
import { startChatEventRetention } from './api/chat/retention';

mkdirSync(DATA_PATH, { recursive: true });
ensureItemDirs();

(async () => {
  ensureToolLoader();
  // Queue is initialized by the sidecar process

  startChatEventRetention();

  await startDiscordBotIfConfigured().catch((err) => {
    console.error('[channels] Failed to start Discord bot:', err);
  });

  await startTelegramBotIfConfigured().catch((err) => {
    console.error('[channels] Failed to start Telegram bot:', err);
  });

  await startWhatsAppBotIfConfigured().catch((err) => {
    console.error('[channels] Failed to start WhatsApp bot:', err);
  });
})();
