import { Queue } from "bullmq";
import { redisConnection } from "../../lib/redis.js";
import {
  PUSH_BROADCAST_JOB_NAME,
  PUSH_QUEUE_NAME,
  PUSH_SIGNAL_JOB_NAME
} from "./queue.constants.js";
import type {
  PushBroadcastJobData,
  PushJobData,
  PushSignalJobData
} from "./queue.types.js";

export const pushQueue = new Queue<PushJobData>(PUSH_QUEUE_NAME, {
  connection: redisConnection,
  defaultJobOptions: {
    attempts: 5,
    backoff: {
      type: "exponential",
      delay: 5_000
    },
    removeOnComplete: 500,
    removeOnFail: 500
  }
});

export async function enqueueSignalPush(payload: PushSignalJobData) {
  return pushQueue.add(PUSH_SIGNAL_JOB_NAME, payload);
}

export async function enqueueBroadcastPush(payload: PushBroadcastJobData) {
  return pushQueue.add(PUSH_BROADCAST_JOB_NAME, payload);
}
