import type { ServerWebSocket } from "bun";
import type { WebSocketData } from "@WS/.";
import { _n } from "@/client-exports";
import sendData from "../../../utils/send-data";
import getQueue from "@/package-shared/functions/backend/queues/get-queue";
import { DSQL_DATASQUIREL_PROCESS_QUEUE } from "@/package-shared/types/dsql";

type Param = {
    ws: ServerWebSocket<WebSocketData>;
};

export default async function checkQueue({ ws }: Param) {
    try {
        const user = ws.data.user;
        const queue = (await getQueue({
            userId: user.id,
            single: true,
        })) as DSQL_DATASQUIREL_PROCESS_QUEUE | undefined;

        sendData(ws, {
            event: "server:queue",
            data: {
                queue,
            },
        });
    } catch (error: any) {
        sendData(ws, {
            event: "server:queue",
            data: {
                queue: undefined,
            },
        });
    }
}
