const { Queue } = require("bullmq")

const connection = {
  host: process.env.REDIS_HOST ,
  port: Number(process.env.REDIS_PORT ),
}

const queue = new Queue("deal-classification", { connection })

async function enqueueDealClassification({ dealId }) {
  return queue.add(
    "classify-deal",
    { dealId },
    {
      jobId: `deal-${dealId}`, // aynı deal için duplicate engeller
      attempts: 5,
      backoff: { type: "exponential", delay: 5000 },
      removeOnComplete: 1000,
      removeOnFail: 2000,
    }
  )
}

module.exports = { enqueueDealClassification, connection, queue }
