/**
 * Vendor Assessment Status/Detail Proxy
 */

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

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

export async function GET(
  _request: NextRequest,
  { params }: { params: Promise<{ id: string }> },
) {
  const { id } = await params
  try {
    const resp = await fetch(
      `${BACKEND_URL}/api/vendor-compliance/assessments/${id}`,
      { signal: AbortSignal.timeout(10000) },
    )
    const data = await resp.json()
    return NextResponse.json(data, { status: resp.status })
  } catch (error) {
    console.error('Assessment status proxy error:', error)
    return NextResponse.json(
      { error: 'Backend nicht erreichbar' },
      { status: 503 },
    )
  }
}

export async function POST(
  _request: NextRequest,
  { params }: { params: Promise<{ id: string }> },
) {
  const { id } = await params
  try {
    const resp = await fetch(
      `${BACKEND_URL}/api/vendor-compliance/assessments/${id}/approve`,
      {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        signal: AbortSignal.timeout(10000),
      },
    )
    const data = await resp.json()
    return NextResponse.json(data, { status: resp.status })
  } catch (error) {
    console.error('Assessment approve proxy error:', error)
    return NextResponse.json(
      { error: 'Backend nicht erreichbar' },
      { status: 503 },
    )
  }
}
