import { NextResponse } from "next/server";
import { getSyncStatus } from "@/modules/parcel-sync/services/sync-service";

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

/**
 * GET /api/eterra/sync-status?siruta=...
 * Returns sync run history & local feature counts per layer.
 */
export async function GET(req: Request) {
  try {
    const url = new URL(req.url);
    const siruta = url.searchParams.get("siruta");
    if (!siruta || !/^\d+$/.test(siruta)) {
      return NextResponse.json({ error: "SIRUTA invalid" }, { status: 400 });
    }

    const status = await getSyncStatus(siruta);
    return NextResponse.json(status);
  } catch (error) {
    const message = error instanceof Error ? error.message : "Eroare server";
    return NextResponse.json({ error: message }, { status: 500 });
  }
}
