const connectionRoute = require("./connection");
const messageRoute = require("./message");

const routes = {
    connection: connectionRoute,
    message: messageRoute,
};

function routeMessage(wss, ws, message) {
    const handler = routes[message.event];
    if (handler) {
        handler(wss, ws, message);
    } else {
        ws.send(JSON.stringify({ error: `Unknown event: ${message.event}` }));
    }
}

module.exports = { routeMessage };