/**
 * Proxy TOTP setup to platform-service.
 * POST /api/auth/mfa/totp/setup
 */

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

const PLATFORM_API = process.env.PLATFORM_SERVICE_URL || 'http://localhost:4003';

export async function POST(req: NextRequest) {
  try {
    const auth = req.headers.get('authorization') || '';
    const res = await fetch(`${PLATFORM_API}/api/auth/mfa/totp/setup`, {
      method: 'POST',
      headers: { Authorization: auth, 'Content-Type': 'application/json' },
    });
    const data = await res.json();
    if (!res.ok) {
      return NextResponse.json(
        { error: data.error || 'TOTP setup failed' },
        { status: res.status }
      );
    }
    return NextResponse.json(data);
  } catch {
    return NextResponse.json({ error: 'Platform service unavailable' }, { status: 502 });
  }
}
