import { Queue } from 'bullmq';
import { sharedRedisConnection } from './redisConnection';
import logger from '@utils/logger';

let tatQueue: Queue | null = null;

try {
  // Use shared Redis connection for both Queue and Worker
  tatQueue = new Queue('tatQueue', {
    connection: sharedRedisConnection,
    defaultJobOptions: {
      removeOnComplete: true,
      removeOnFail: false,
      attempts: 2,
      backoff: {
        type: 'fixed',
        delay: 5000
      }
    }
  });
  
  tatQueue.on('error', (error) => {
    logger.error('[TAT Queue] Queue error:', error);
  });

  logger.info('[TAT Queue] ✅ Queue initialized');
} catch (error) {
  logger.error('[TAT Queue] Failed to initialize:', error);
  tatQueue = null;
}

export { tatQueue };

