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

interface Body {
    id: string;
    siteId: string;
    name: string;
    ipv4Subnet?: string;
    ipv6Subnet?: string;
    gateway?: string;
}

export async function POST(request: NextRequest) {
    const body: Body = await request.json();

    try {
        const network = await prisma.network.create({
            data: {
                siteId: Number(body.siteId),
                name: body.name,
                ipv4Subnet: body.ipv4Subnet,
                ipv6Subnet: body.ipv6Subnet,
                gateway: body.gateway,
            },
        });

        return NextResponse.json({ network }, { status: 201 });
    } catch (error) {
        console.error("Error creating network:", error);
        return NextResponse.json({ error: "Failed to create network" }, { status: 500 });
    }
}
