import { NextRequest, NextResponse } from "next/server";
import { getCurrentUser } from "@/lib/auth";
import { getStatementCoverage } from "@/lib/queries";

/**
 * How far each account's statements already reach.
 *
 * Read by the CSV import modal so it can drop rows the ledger already holds.
 * The first Frollo import went in without this and wrote 422 duplicates out of
 * 550 — the same payments the statements already carried, itemised and
 * converted. On the 2026-08-13 export the rule takes 2,607 rows down to 171.
 */
export async function GET(req: NextRequest) {
  const user = await getCurrentUser(req);
  if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 403 });
  return NextResponse.json({ coverage: await getStatementCoverage() });
}
