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

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

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

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

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

    } 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 });
    }
}
    