const { getRedisClient } = require("./client")

const NOTIFICATIONS_CHANNEL = "notifications"

function createRedisClient() {
  return getRedisClient()
}

async function publishNotification(payload) {
  if (!payload) return 0
  const redis = createRedisClient()
  try {
    const message = JSON.stringify(payload)
    return await redis.publish(NOTIFICATIONS_CHANNEL, message)
  } finally {}
}

module.exports = { publishNotification, NOTIFICATIONS_CHANNEL }
