import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export default defineEventHandler( async (event) => {
    console.log("This is a test for a DELETE request to the backend");

    const { cabinet_id } = await readBody(event);

    if (!cabinet_id) {
        return {
            status: 400,
            message: "cabinet_id was not provided. No folder was deleted."
        };
    };

    const foundFolder = await prisma.cabinets.findUnique({
        where: {
            cb_id: cabinet_id
        }
    });

    if (!foundFolder) {
        return {
            status: 404,
            message: "Folder not found. No folder was deleted."
        }
    } else {
        const deletedFolder = await prisma.cabinets.delete({
            where: {
                cb_id: cabinet_id
            }
        });
        return {
            status: 200,
            message: "Folder deleted successfully",
            folder: deletedFolder
        };
    }
});