// lib/generate-name.ts
import crypto from "crypto";

const ADJECTIVES = [
  "swift", "quiet", "bold", "amber", "lucky", "clever", "brave", "calm",
  "eager", "fuzzy", "gentle", "happy", "jolly", "kind", "lively", "misty",
  "noble", "proud", "quick", "royal", "sunny", "tidy", "vivid", "witty",
  "cosmic", "crimson", "golden", "silver", "violet", "crystal",
];

const NOUNS = [
  "otter", "falcon", "tiger", "maple", "harbor", "comet", "willow", "canyon",
  "meadow", "ember", "glacier", "phoenix", "raven", "summit", "cedar",
  "lagoon", "prairie", "quartz", "sparrow", "thunder", "voyage", "zephyr",
  "beacon", "drift", "echo", "flint", "grove", "haven", "isle", "jet",
];

/**
 * Generates a human-friendly random local-part for a temp email,
 * e.g. "swift-otter-4821". Collision risk is mitigated by the numeric
 * suffix and by the caller re-checking uniqueness against the DB.
 */
export function generateRandomPrefix(): string {
  const adjective = ADJECTIVES[crypto.randomInt(0, ADJECTIVES.length)];
  const noun = NOUNS[crypto.randomInt(0, NOUNS.length)];
  const suffix = crypto.randomInt(1000, 9999);
  return `${adjective}-${noun}-${suffix}`;
}
