import { deleteMailConnection, deleteAllMailConnections } from "../../db/mail";

/**
 * DELETE /api/mail/disconnect
 * Trennt das Gmail-Konto (löscht Connection und alle Logs).
 */
export default defineEventHandler(async (event) => {
  const user = await requireUser(event);

  const { connectionId } = await readBody(event).catch(() => ({}));

  if (connectionId) {
    await deleteMailConnection(user.id, connectionId);
  } else {
    await deleteAllMailConnections(user.id);
  }

  return { ok: true };
});
