import { NextRequest, NextResponse } from 'next/server'
const CONSENT_URL = process.env.CONSENT_TESTER_URL || 'http://bp-compliance-consent-tester:8094'

export async function POST(request: NextRequest) {
  try {
    const body = await request.text()
    const response = await fetch(`${CONSENT_URL}/authenticated-scan`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body,
      signal: AbortSignal.timeout(120000),
    })
    if (!response.ok) {
      return NextResponse.json({ error: `Auth-Test: ${response.status}` }, { status: response.status })
    }
    return NextResponse.json(await response.json())
  } catch (error) {
    return NextResponse.json({ error: 'Auth-Test fehlgeschlagen' }, { status: 503 })
  }
}
