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

const SDK_URL = process.env.SDK_URL || 'http://ai-compliance-sdk:8090'

export async function GET(request: NextRequest) {
  try {
    const tenantId = request.headers.get('x-tenant-id') || '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e'
    const resp = await fetch(`${SDK_URL}/sdk/v1/payment-compliance/tender`, {
      headers: { 'X-Tenant-ID': tenantId },
    })
    return NextResponse.json(await resp.json())
  } catch {
    return NextResponse.json({ error: 'Failed' }, { status: 500 })
  }
}

export async function POST(request: NextRequest) {
  try {
    const tenantId = request.headers.get('x-tenant-id') || '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e'
    const formData = await request.formData()
    const resp = await fetch(`${SDK_URL}/sdk/v1/payment-compliance/tender/upload`, {
      method: 'POST',
      headers: { 'X-Tenant-ID': tenantId },
      body: formData,
    })
    return NextResponse.json(await resp.json(), { status: resp.status })
  } catch {
    return NextResponse.json({ error: 'Upload failed' }, { status: 500 })
  }
}
