import { NextResponse } from "next/server";
import { getProjectConfigs, loadTasks } from "@/lib/autobuilder";

export const dynamic = "force-dynamic";

export async function GET(
  _req: Request,
  { params }: { params: Promise<{ id: string; initId: string }> }
) {
  const { id, initId } = await params;
  const configs = await getProjectConfigs();
  const cfg = configs.find((c) => c.name === id);
  if (!cfg) return NextResponse.json({ error: "Project not found" }, { status: 404 });

  const tasks = await loadTasks(cfg.autobuilderDir, initId);
  return NextResponse.json(tasks);
}
