import { NextRequest, NextResponse } from "next/server";
import prisma from "@/app/prisma";
import { z } from "zod/v4";

const schema = z.object({
    notificationId: z.string(),
});

export async function DELETE(request: NextRequest) {
    const searchParams = request.nextUrl.searchParams;
    const notificationId = schema.parse({ notificationId: searchParams.get("notificationId") });

    try {
        const notification = await prisma.notificationProvider.delete({
            where: { id: parseInt(notificationId.notificationId) },
        });

        return NextResponse.json(notification);
    } catch (error: any) {
        if(error instanceof z.ZodError) {
            return NextResponse.json({ error: error.issues[0].message }, { status: 400 });
        }
        return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
    }
}