import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export async function POST(request: NextRequest) {
  try {
    const body = await request.json();
    const { stats, model } = body;
    if (!stats || !stats.repoName) {
      return NextResponse.json({ error: "Stats manquantes" }, { status: 400 });
    }

    const { generateAISummary } = await import("@/lib/git-analyzer");
    const summary = await generateAISummary(stats, model || undefined);

    return NextResponse.json({ summary });
  } catch (error: any) {
    return NextResponse.json({ error: error?.message || "Erreur" }, { status: 500 });
  }
}
