export function registerRealtime(io) {
  io.on("connection", (socket) => {
    socket.on("user:join", ({ userId, role }) => {
      if (userId) socket.join(String(userId));
      if (role === "admin" || role === "super_admin") socket.join("admins");
      if (role === "support") socket.join("support");
    });

    socket.on("chat:message", (message) => {
      io.to(message.roomId).emit("chat:message", { ...message, deliveredAt: new Date().toISOString() });
    });

    socket.on("flash-sale:tick", (payload) => {
      io.emit("flash-sale:tick", payload);
    });
  });
}
