import { NextResponse } from "next/server";
import { DocumentReadError, UnsupportedFileTypeError } from "@/lib/ingest/acceptedTypes";

/** Maps processor/extractor failures to a typed HTTP response. */
export function jsonForScanError(error: unknown): NextResponse {
  if (error instanceof UnsupportedFileTypeError) {
    return NextResponse.json({ error: error.message }, { status: 415 });
  }
  if (error instanceof DocumentReadError) {
    return NextResponse.json({ error: error.message }, { status: 422 });
  }
  console.error("Scan route error:", error);
  return NextResponse.json(
    { error: "Fehler bei der Belegverarbeitung" },
    { status: 500 }
  );
}
