/**
 * GET /api/scan/status/<checkId>
 *   Proxy to compliance backend /api/compliance/agent/compliance-check/<id>.
 *
 * Polled every ~5s by the savings-scan page until status==completed/failed.
 */
import { NextRequest, NextResponse } from 'next/server'

const BACKEND_URL =
  process.env.COMPLIANCE_BACKEND_URL || 'https://api-dev.breakpilot.ai'

export async function GET(
  _request: NextRequest,
  { params }: { params: Promise<{ checkId: string }> },
) {
  const { checkId } = await params
  try {
    const res = await fetch(
      `${BACKEND_URL}/api/compliance/agent/compliance-check/${checkId}`,
      { signal: AbortSignal.timeout(15000) },
    )
    const data = await res.json().catch(() => ({}))
    return NextResponse.json(data, { status: res.status })
  } catch {
    return NextResponse.json(
      { error: 'Backend nicht erreichbar' }, { status: 503 },
    )
  }
}
