/**
 * Agent Notify API Proxy
 * POST /api/sdk/v1/agent/notify → backend-compliance /api/compliance/agent/notify
 */

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

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

export async function POST(request: NextRequest) {
  try {
    const body = await request.text()
    const response = await fetch(`${BACKEND_URL}/api/compliance/agent/notify`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body,
      signal: AbortSignal.timeout(15000),
    })

    if (!response.ok) {
      const errorText = await response.text()
      return NextResponse.json({ error: errorText }, { status: response.status })
    }

    return NextResponse.json(await response.json())
  } catch (error) {
    console.error('Agent notify proxy error:', error)
    return NextResponse.json({ error: 'Email-Versand fehlgeschlagen' }, { status: 503 })
  }
}
