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

export const dynamic = 'force-dynamic';

const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000';

/** Desk pack proxy (Session 63 / A1-S4) — forwards the founder's auth. */
export async function GET(req: NextRequest) {
  const auth = req.headers.get('authorization');
  if (!auth) return NextResponse.json({ error: 'auth required' }, { status: 401 });
  try {
    const upstream = await fetch(`${BACKEND_URL}/api/desk/pack`, {
      headers: { Accept: 'application/json', Authorization: auth },
      cache: 'no-store',
    });
    const data = await upstream.json().catch(() => ({}));
    return NextResponse.json(data, { status: upstream.status });
  } catch {
    return NextResponse.json({ error: 'desk unavailable' }, { status: 200 });
  }
}
