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

const BACKEND_URL = process.env.CONSENT_BACKEND_URL || 'https://macmini:3007/api/sdk/v1/banner'
const TENANT_ID = process.env.CONSENT_TENANT_ID || '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e'
const SITE_ID = process.env.NEXT_PUBLIC_CONSENT_SITE_ID || 'breakpilot-marketing'

export async function GET(req: NextRequest) {
  try {
    const siteId = req.nextUrl.searchParams.get('site_id') || SITE_ID
    const res = await fetch(`${BACKEND_URL}/config/${siteId}`, {
      headers: { 'X-Tenant-ID': TENANT_ID },
    })
    const data = await res.text()
    return new NextResponse(data, {
      status: res.status,
      headers: { 'Content-Type': 'application/json' },
    })
  } catch {
    return NextResponse.json({ categories: [], vendors: [] }, { status: 200 })
  }
}
