import { NextRequest, NextResponse } from "next/server"; import { requireAdminUser } from "@/lib/auth/middleware"; import { generateItemStructure } from "@/lib/ai/generate-item-structure"; export async function POST(request: NextRequest) { const auth = await requireAdminUser(request); if (auth instanceof NextResponse) { return auth; } const body = await request.json(); const name = typeof body?.name === "string" ? body.name.trim() : ""; const description = typeof body?.description === "string" ? body.description.trim() : ""; const scope = body?.scope === "server" ? "server" : "global"; const server = scope === "server" && typeof body?.server === "string" ? body.server.trim() : null; if (!name || !description) { return NextResponse.json( { success: false, error: "Informe nome e descrição para gerar o JSON estrutural.", }, { status: 400 } ); } const result = await generateItemStructure({ name, description, scope, server, }); return NextResponse.json( { success: true, structure: result.structure, }, { status: 200 } ); }