import { NextResponse } from "next/server";
import { scoreAdCopy } from "@/lib/ml/bad-ads-strategy";

export async function POST(req: Request) {
  try {
    const { text } = (await req.json()) as { text?: string };
    if (!text?.trim()) {
      return NextResponse.json({ error: "Missing ad copy text" }, { status: 400 });
    }
    const score = scoreAdCopy(text);
    return NextResponse.json({ score });
  } catch {
    return NextResponse.json({ error: "Scoring failed" }, { status: 500 });
  }
}
