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

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

export default async function webSocketSendDummyQueue({ ws }: Param) {
    try {
        console.log("Sending Dummy Queue ...");

        const user = ws.data.user;
        const dummyQueue = await addQueue({
            queue: {
                job_type: "dummy",
                user_id: user.id,
                title: "Running Dummy Queue ...",
            },
            userId: user.id,
            dummy: true,
        });

        await Bun.sleep(2000);

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