import { NextRequest, NextResponse } from "next/server";
import prisma from "@/app/prisma";
import { Network } from "@/app/types";

interface Body {
    id: string;
    name: string;
    description: string;
    networks: Network[];
}

export async function POST(request: NextRequest) {
    const body: Body = await request.json();
    const { id, name, description, networks } = body;

    try {
        const site = await prisma.site.update({
            where: { id: Number(id) },
            data: { name, description },
        });

        return NextResponse.json(site);
    } catch (error) {
        console.error(error);
        return NextResponse.json({ error: "Failed to update site" }, { status: 500 });
    }
}
