/**
 * Proxy passkey delete to platform-service.
 * DELETE /api/auth/passkeys/:id
 */

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

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

export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
  try {
    const { id } = await params;
    const auth = req.headers.get('authorization') || '';
    const res = await fetch(`${PLATFORM_API}/api/auth/passkeys/${id}`, {
      method: 'DELETE',
      headers: { Authorization: auth },
    });
    const data = await res.json();
    if (!res.ok) {
      return NextResponse.json(
        { error: data.error || 'Failed to delete passkey' },
        { status: res.status }
      );
    }
    return NextResponse.json(data);
  } catch {
    return NextResponse.json({ error: 'Platform service unavailable' }, { status: 502 });
  }
}
