/**
 * Vendor Assessment API Proxy
 * Proxies to backend-compliance (Python FastAPI)
 */

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

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

export async function POST(request: NextRequest) {
  try {
    const body = await request.text()
    const resp = await fetch(`${BACKEND_URL}/api/vendor-compliance/assessments`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body,
      signal: AbortSignal.timeout(10000),
    })
    const data = await resp.json()
    return NextResponse.json(data, { status: resp.status })
  } catch (error) {
    console.error('Vendor assessment proxy error:', error)
    return NextResponse.json(
      { error: 'Backend nicht erreichbar' },
      { status: 503 },
    )
  }
}

export async function GET() {
  try {
    const resp = await fetch(`${BACKEND_URL}/api/vendor-compliance/assessments`, {
      signal: AbortSignal.timeout(10000),
    })
    const data = await resp.json()
    return NextResponse.json(data)
  } catch (error) {
    console.error('Vendor assessment list proxy error:', error)
    return NextResponse.json({ assessments: [] })
  }
}
