/**
 * Impressum-Analyse-Proxy
 * GET /api/sdk/v1/agent/snapshots/{snapshotId}/impressum-check
 *   → backend /api/compliance/agent/snapshots/{snapshotId}/impressum-check
 *
 * Laeuft den v3 ImpressumAgent auf dem gespeicherten Impressum-Text
 * (kein Re-Crawl) und liefert den AgentOutput (Findings/Massnahmen/Coverage).
 */

import { NextRequest, NextResponse } from 'next/server'

const BACKEND_URL =
  process.env.BACKEND_API_URL || process.env.BACKEND_URL ||
  'http://backend-compliance:8002'

export async function GET(
  _request: NextRequest,
  { params }: { params: Promise<{ snapshotId: string }> },
) {
  const { snapshotId } = await params
  try {
    const response = await fetch(
      `${BACKEND_URL}/api/compliance/agent/snapshots/${snapshotId}/impressum-check`,
      { signal: AbortSignal.timeout(120_000) },
    )
    const data = await response.json()
    return NextResponse.json(data, { status: response.status })
  } catch {
    return NextResponse.json(
      { error: 'Impressum-Analyse fehlgeschlagen', findings: [] },
      { status: 503 },
    )
  }
}
