// ═══════════════════════════════════════════════════════════════════════════════
// SCHEDULER ADDITION — competition auto-winner & bonus payout cron
// ADD these lines to scheduler.js INSIDE the start() function,
// just before the closing console.log line
// ═══════════════════════════════════════════════════════════════════════════════

// ─── Competition auto-winner & social contest bonus scheduler ─────────────────
const { runCompetitionScheduler } = require('./competition_module');

// Runs every hour
// - Auto-selects winners for competitions 72hrs past deadline with no winner picked
// - Pays out social contest bonus prizes 7 days after deadline
const _compNotify = async (telegramId, msg) => {
  // Use same bot token approach as existing scheduler notifications
  // Replace with your actual notify function if scheduler has one
  try {
    const axios = require('axios');
    await axios.post(`https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`, {
      chat_id: String(telegramId),
      text: msg,
      parse_mode: 'HTML',
    });
  } catch (e) { /* silent */ }
};

setInterval(async () => {
  try {
    await runCompetitionScheduler(supabase, db, _compNotify, fmt);
  } catch (e) {
    console.error('[Scheduler] Competition scheduler error:', e.message);
  }
}, 60 * 60 * 1000); // every 60 minutes

console.log('[Scheduler] Competition scheduler registered (runs hourly)');

// ═══════════════════════════════════════════════════════════════════════════════
// EXACT PLACEMENT in scheduler.js:
// Find this line near the bottom of start():
//   console.log(`[Scheduler] Started! Next daily summary in ${Math.round(msUntilMidnight / 3600000)}h`);
// Add the setInterval block ABOVE that line.
// ═══════════════════════════════════════════════════════════════════════════════
