let io = null;

export function setIO(instance) {
  io = instance;
}

export function getIO() {
  return io;
}

export function emitJackpot(roundId, event, payload) {
  if (!io) return;
  const id = Number(roundId);
  if (id) {
    io.to(`jackpot:${id}`).emit(event, payload);
  }
  // Legacy global room
  io.to('jackpot').emit(event, payload);
  // Hub list subscribers need spin/result for live cards
  if (event === 'jackpot:spin' || event === 'jackpot:result') {
    io.to('jackpots').emit(event, payload);
  }
}

export function emitJackpotsList(payload) {
  if (!io) return;
  io.to('jackpots').emit('jackpots:list', payload);
}
