import cron from 'node-cron';
import { addJob } from './queue';

// 启动调度器
export const startScheduler = (): void => {
  console.log('[Scheduler] Starting scheduler...');
  
  // 每5分钟同步库存
  cron.schedule('*/5 * * * *', () => {
    console.log('[Scheduler] Running inventory sync...');
    addJob('SYNC_INVENTORY', {});
  });
  
  // 每1小时计算ROI
  cron.schedule('0 * * * *', () => {
    console.log('[Scheduler] Running ROI calculation...');
    addJob('CALCULATE_PROFIT', {});
  });
  
  // 每天凌晨1点生成账单
  cron.schedule('0 1 * * *', () => {
    console.log('[Scheduler] Generating bills...');
    // 这里应该获取所有商户并为每个商户生成账单
    // 暂时创建一个示例任务
    addJob('GENERATE_BILL', {});
  });
  
  console.log('[Scheduler] Scheduler started successfully');
};

export default {
  startScheduler
};
