import dsqlCrud from "../../../utils/data-fetching/crud";
import getQueue from "./get-queue";
import {
    DSQL_DATASQUIREL_PROCESS_QUEUE,
    DsqlTables,
} from "../../../types/dsql";

type Param = {
    queueId: string | number;
    userId: string | number;
};

export default async function deleteQueue({ queueId, userId }: Param) {
    const tableName: (typeof DsqlTables)[number] = "process_queue";

    const existingQueue = (await getQueue({ userId, queueId })) as
        | DSQL_DATASQUIREL_PROCESS_QUEUE
        | undefined;

    if (!existingQueue?.id) return false;

    const deleteQueueRes = await dsqlCrud<DSQL_DATASQUIREL_PROCESS_QUEUE>({
        action: "delete",
        table: tableName,
        targetId: existingQueue.id,
    });

    return Boolean(deleteQueueRes?.success);
}
