import { NextRequest, NextResponse } from 'next/server'
import { springProxy } from '@/lib/springProxy'

export async function POST(req: NextRequest) {
  let body: unknown
  try {
    body = await req.json()
  } catch {
    return NextResponse.json({ error: 'Invalid request' }, { status: 400 })
  }

  const ip =
    req.headers.get('x-forwarded-for')?.split(',')[0]?.trim() ??
    req.headers.get('x-real-ip') ??
    'unknown'
  const userAgent = req.headers.get('user-agent') ?? 'unknown'

  return springProxy(req, '/api/v1/feedback', {
    method: 'POST',
    body: { ...(body as object), ipAddress: ip, userAgent },
  })
}
