import { NextResponse } from "next/server";
import { db, userAiKeys, eq, and } from "@epicure/db";
import { requireByok } from "@/lib/api-auth";

type Params = { params: Promise<{ provider: string }> };

export async function DELETE(_req: Request, { params }: Params) {
  const { session, response } = await requireByok();
  if (response) return response;

  const { provider } = await params;

  await db.delete(userAiKeys).where(
    and(eq(userAiKeys.userId, session!.user.id), eq(userAiKeys.provider, provider))
  );

  return NextResponse.json({ ok: true });
}
