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

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

export default async function webSocketDeleteQueue({ ws, data }: Param) {
    try {
        const user = ws.data.user;

        await deleteQueue({
            queueId: _n(data?.data?.queue?.id),
            userId: user.id,
        });

        await Bun.sleep(2000);

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