require("dotenv").config()
const { startDealClassificationWorker } = require("./dealClassification.worker")
const { queue } = require("../jobs/dealClassification.queue")
const { startHotDealListWorker } = require("./hotDealList.worker")
const { ensureHotDealListRepeatable } = require("../jobs/hotDealList.queue")
const { startTrendingDealListWorker } = require("./trendingDealList.worker")
const { ensureTrendingDealListRepeatable } = require("../jobs/trendingDealList.queue")
const { startNewDealListWorker } = require("./newDealList.worker")
const { ensureNewDealListRepeatable } = require("../jobs/newDealList.queue")
const { startDbSyncWorker } = require("./dbSync.worker")
const { ensureDbSyncRepeatable } = require("../jobs/dbSync.queue")

startDealClassificationWorker()
console.log("Worker started: deal-classification")
startHotDealListWorker()
console.log("Worker started: hotdeal-list")
startTrendingDealListWorker()
console.log("Worker started: trendingdeal-list")
startNewDealListWorker()
console.log("Worker started: newdeal-list")
startDbSyncWorker()
console.log("Worker started: db-sync")

ensureHotDealListRepeatable().catch((err) =>
  console.error("âŒ hotdeal repeatable setup failed", err?.message || err)
)
ensureTrendingDealListRepeatable().catch((err) =>
  console.error("âŒ trending repeatable setup failed", err?.message || err)
)
ensureNewDealListRepeatable().catch((err) =>
  console.error("âŒ newdeal repeatable setup failed", err?.message || err)
)
ensureDbSyncRepeatable().catch((err) =>
  console.error("âŒ db-sync repeatable setup failed", err?.message || err)
)

setInterval(async () => {
  const counts = await queue.getJobCounts("waiting", "active", "completed", "failed", "delayed", "paused")
  console.log("queue counts:", counts)
}, 3000)
