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

const schema = z.object({
    networkId: z.number(),
});

export async function DELETE(request: NextRequest) {
    const searchParams = request.nextUrl.searchParams;
    const network = schema.parse({ networkId: searchParams.get("networkId") });
    
    try {
        await prisma.network.delete({
            where: {
                id: network.networkId,
            },
        });
        
        return NextResponse.json({ message: "Network deleted successfully" });
    } 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 });
    }
}