import { pauseResumeSchedulerService } from '../services/pauseResumeScheduler.service';
import { pauseResumeWorker } from '../queues/pauseResumeWorker';
import logger from '../utils/logger';

/**
 * Initialize pause resume job system using BullMQ (Redis)
 * This schedules a recurring job that runs every hour to auto-resume paused workflows
 */
export async function startPauseResumeJob(): Promise<void> {
  try {
    // Initialize the worker (listens for jobs)
    if (pauseResumeWorker) {
      logger.info('[Pause Resume Job] ✅ Worker initialized');
    } else {
      logger.warn('[Pause Resume Job] ⚠️ Worker not available (Redis may not be connected)');
    }

    // Schedule the recurring auto-resume job
    await pauseResumeSchedulerService.scheduleAutoResumeJob();
  } catch (error: any) {
    logger.error('[Pause Resume Job] Failed to start pause resume job system:', error);
    // Don't throw - allow server to start even if Redis is not available
  }
}

