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

export interface KevoPostCallJobData {
  conversationId: string;
}

export const KEVO_POSTCALL_QUEUE = "kevo-postcall";

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

export function getKevoPostCallQueue(): Queue<KevoPostCallJobData> {
  if (!_queue) {
    _queue = new Queue<KevoPostCallJobData>(KEVO_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("[KevoPostCallQueue] Queue error:", err);
    });
  }
  return _queue;
}
