import { NextResponse } from "next/server";
import { getProgress } from "@/modules/parcel-sync/services/progress-store";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

/**
 * GET /api/eterra/progress?jobId=...
 * Poll sync progress for a running job.
 */
export async function GET(req: Request) {
  const url = new URL(req.url);
  const jobId = url.searchParams.get("jobId");
  if (!jobId) {
    return NextResponse.json({ error: "jobId obligatoriu" }, { status: 400 });
  }

  const progress = getProgress(jobId);
  if (!progress) {
    return NextResponse.json({ jobId, status: "unknown" });
  }

  return NextResponse.json(progress);
}
