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

const LEGAL_SERVICE = process.env.LEGAL_SERVICE_URL ?? 'http://localhost:3200'

// Proxy multipart upload to legal-service document ingestion endpoint.
// The legal-service assigns Bates numbers, persists to object storage,
// and enqueues each document for AI classification.
export async function POST(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params
  const formData = await req.formData()
  const res = await fetch(`${LEGAL_SERVICE}/client-folders/${id}/documents/upload`, {
    method: 'POST',
    body: formData,
    // Do not set Content-Type — let fetch set the multipart boundary automatically
  })
  const data = await res.json()
  return NextResponse.json(data, { status: res.status })
}
