import { randomUUID } from 'node:crypto';

/**
 * A person registered without a login — a dormitory walk-in, typically —
 * still needs a User row, and User.email is unique and required. They get
 * an address under a reserved domain (RFC 2606 `.invalid` never resolves),
 * `hasLogin = false`, and a password nobody knows. Sign-in refuses the
 * account and every email send skips the address, so the placeholder can
 * never leak out as mail or be guessed into.
 */
export const NO_LOGIN_EMAIL_DOMAIN = 'no-login.hostelcare.invalid';

export const placeholderEmail = () => `walk-in.${randomUUID()}@${NO_LOGIN_EMAIL_DOMAIN}`;

export const isPlaceholderEmail = (email: string | null | undefined) =>
  !!email && email.toLowerCase().endsWith(`@${NO_LOGIN_EMAIL_DOMAIN}`);
