import { NextResponse } from 'next/server';
import { verifyAdmin } from '@/lib/password';
import { revokeApiKey } from '@/lib/api-keys';

// DELETE /api/auth/keys/:id — revoke a key; requires the admin password (in body)
export async function DELETE(req: Request, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const body = await req.json().catch(() => ({}));
  const { adminPassword } = body as { adminPassword?: string };

  if (!verifyAdmin(adminPassword || '')) {
    return NextResponse.json({ error: 'Invalid admin password' }, { status: 403 });
  }
  const ok = revokeApiKey(id);
  return NextResponse.json({ ok });
}
