/**
 * Proxy: GET /api/sdk/v1/agent/findings/<checkId>
 *   -> backend GET /api/compliance/agent/findings/<checkId>
 *
 * Forwards all query params (source, severity, doc_type, status, q, limit).
 */
import { NextRequest, NextResponse } from 'next/server'

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

export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ checkId: string }> },
) {
  const { checkId } = await params
  const qs = request.nextUrl.searchParams.toString()
  const url = `${BACKEND_URL}/api/compliance/agent/findings/${checkId}${qs ? `?${qs}` : ''}`
  try {
    const resp = await fetch(url, { signal: AbortSignal.timeout(20000) })
    const data = await resp.json()
    return NextResponse.json(data, { status: resp.status })
  } catch {
    return NextResponse.json(
      { error: 'Findings-Abfrage fehlgeschlagen' },
      { status: 503 },
    )
  }
}
