import { DomainError } from "../../shared/errors.ts";

export function normalizeEmail(email: string): string {
  const normalized = email.trim().toLowerCase();
  if (normalized.length > 254 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalized)) {
    throw new DomainError("INVALID_EMAIL", "Enter a valid email address.");
  }
  return normalized;
}

export function normalizeDisplayName(name: string): string {
  const normalized = name.trim().replace(/\s+/g, " ");
  if (normalized.length < 2 || normalized.length > 80) throw new DomainError("INVALID_DISPLAY_NAME", "Display name must contain 2 to 80 characters.");
  return normalized;
}
