import { deleteUserCustomDomain } from "../../db/domains";

export default defineEventHandler(async (event) => {
  const user = await requireUser(event);
  const id = getRouterParam(event, "id");

  if (!id) throw createError({ statusCode: 400, message: "ID fehlt" });

  try {
    await deleteUserCustomDomain(id, user.id);
  } catch (err: any) {
    if (err.code === "P2025") {
      throw createError({ statusCode: 404, message: "Domain nicht gefunden" });
    }
    throw createError({ statusCode: 500, message: err.message });
  }

  return { ok: true };
});
