/**
 * bcrypt hash normalization helper (pure function).
 *
 * Some legacy rows store bcrypt hashes without the leading `$2b$` version
 * marker. `compare` from `bcryptjs` requires a well-formed hash, so we
 * restore the prefix before verification.
 */

/**
 * Normalize a stored bcrypt hash to the canonical `$2b$...` form.
 * - Already-prefixed hashes (`$2a$`, `$2b$`, `$2y$`, ...) are returned as-is.
 * - Hashes starting with `$` but missing the version (e.g. `$abc...`) get `$2b` prepended.
 * - Bare hashes get the full `$2b$` prefix prepended.
 */
export const normalizeBcryptHash = (value: string): string => {
  if (value.startsWith("$2")) return value
  if (value.startsWith("$")) return `$2b${value}`
  return `$2b$${value}`
}
