/**
 * POST /api/schema/validate — Validate JSON-LD schema markup.
 */
import { NextResponse } from "next/server";
import { getCurrentUser } from "@/lib/auth";
import { validateSchema } from "@/lib/services/schema-generator";

export const dynamic = "force-dynamic";

export async function POST(req: Request) {
  const user = await getCurrentUser();
  if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });

  const body = await req.json().catch(() => null);
  if (!body?.jsonLd) return NextResponse.json({ error: "jsonLd required" }, { status: 400 });
  const result = validateSchema(body.jsonLd);
  return NextResponse.json(result);
}
