import { getBridgeHealth } from '@/lib/whatsapp.js';
import { listInboundAllowlist } from '@/lib/whatsapp-router.js';
import { requireSession } from '@/lib/auth.js';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

export async function GET(req) {
  try {
    await requireSession(req);
    const health = await getBridgeHealth();
    const allowlist = listInboundAllowlist();
    return Response.json({ ok: true, health, allowlist });
  } catch (err) {
    if (err && typeof err === 'object' && err.status) {
      return Response.json({ error: err.error || 'unauthorized' }, { status: err.status });
    }
    throw err;
  }
}
