import { User } from "@/src/types";
import grabConnectedWebsocketUserdataIndex from "./grab-connected-websocket-user-data-index";

type Params = {
    user: User;
};

export default function grabConnectedWebsocketUserdata({ user }: Params) {
    const connected_user_data_index = grabConnectedWebsocketUserdataIndex({
        user,
    });

    if (typeof connected_user_data_index !== "number") {
        throw new Error(`User Connection Data not found!`);
    }

    const connected_user_data =
        global.WEBSOCKET_CONNECTED_USERS_DATA[connected_user_data_index];

    return connected_user_data;
}
