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

interface Body {
    name: string;
    description: string;
}

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

        if (!body.name) {
            return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
        }

        const site = await prisma.site.create({
            data: {
                name: body.name,
                description: body.description,
            },
        });

        return NextResponse.json({ site }, { status: 201 });

    } catch (error: any) {
        return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
    }
}
    