/**
 * DSMS Gateway Proxy — forwards verify/history requests to dsms-gateway.
 */
import { NextRequest, NextResponse } from 'next/server'

const DSMS_URL = process.env.DSMS_GATEWAY_URL || 'http://dsms-gateway:8082'

export async function GET(request: NextRequest, { params }: { params: Promise<{ path?: string[] }> }) {
  const { path } = await params
  const target = `${DSMS_URL}/api/v1/${(path || []).join('/')}`

  try {
    const resp = await fetch(target, {
      headers: { Authorization: 'Bearer system-frontend' },
      signal: AbortSignal.timeout(15000),
    })
    const data = await resp.json()
    return NextResponse.json(data, { status: resp.status })
  } catch {
    return NextResponse.json({ error: 'DSMS not available' }, { status: 503 })
  }
}
