import { Queue } from "bullmq";
import { getBullMQConnection } from "./notification-target.queue";

export interface GuruPostCallJobData {
  conversationId: string;
}

export const GURU_POSTCALL_QUEUE = "guru-postcall";

let _queue: Queue<GuruPostCallJobData> | null = null;

export function getGuruPostCallQueue(): Queue<GuruPostCallJobData> {
  if (!_queue) {
    _queue = new Queue<GuruPostCallJobData>(GURU_POSTCALL_QUEUE, {
      connection: getBullMQConnection(),
      defaultJobOptions: {
        attempts: 6,
        backoff: { type: "fixed", delay: 2 * 60 * 1000 },
        removeOnComplete: { count: 1000, age: 7 * 24 * 3600 },
        removeOnFail: { count: 1000, age: 7 * 24 * 3600 },
      },
    });
    _queue.on("error", (err) => {
      console.error("[GuruPostCallQueue] Queue error:", err);
    });
  }
  return _queue;
}
