/**
 * Bridges the admin "create user" flow to better-auth's single
 * `sendResetPassword` callback.
 *
 * A brand-new admin-created user is provisioned with a throwaway password and
 * then sent a set-password link via better-auth's password-reset machinery — but
 * the *email* should read as a welcome, not a "you requested a reset". better-auth
 * exposes only one `sendResetPassword` callback (no per-call context), so the
 * create-user service marks the recipient here immediately before triggering the
 * reset; the callback consumes the mark and renders the welcome email instead.
 *
 * Mark and consume happen in the same process within a single synchronous
 * request flow (`createUser` awaits `requestPasswordReset`, which awaits the
 * callback), so this module-level set is safe — it is never read across requests.
 * Keyed by lowercased email; distinct recipients never collide.
 */
const pendingWelcome = new Set<string>();

export function markPendingWelcome(email: string): void {
  pendingWelcome.add(email.toLowerCase());
}

/** Returns true (and clears the mark) when this email was flagged as a welcome. */
export function consumePendingWelcome(email: string): boolean {
  const key = email.toLowerCase();
  const had = pendingWelcome.has(key);
  pendingWelcome.delete(key);
  return had;
}
