/**
 * Audit-Report (strukturiert + Markdown) — Proxy
 * GET /api/sdk/v1/agent/snapshots/{snapshotId}/report
 *   → backend /api/compliance/agent/snapshots/{snapshotId}/report
 */

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 res = await fetch(
      `${BACKEND_URL}/api/compliance/agent/snapshots/${snapshotId}/report`,
      { signal: AbortSignal.timeout(120_000) },
    )
    const data = await res.json()
    return NextResponse.json(data, { status: res.status })
  } catch {
    return NextResponse.json(
      { error: 'Report-Erzeugung fehlgeschlagen' }, { status: 503 })
  }
}
