/**
 * WHMCS Normalization Utilities (domain-internal)
 */

/**
 * Normalize status using provided status map.
 * Generic helper for consistent status mapping.
 */
export function normalizeStatus<T extends string>(
  status: string | null | undefined,
  statusMap: Record<string, T>,
  defaultStatus: T
): T {
  if (!status) return defaultStatus;
  const mapped = statusMap[status.trim().toLowerCase()];
  return mapped ?? defaultStatus;
}

/**
 * Normalize billing cycle using provided cycle map.
 * Generic helper for consistent cycle mapping.
 */
export function normalizeCycle<T extends string>(
  cycle: string | null | undefined,
  cycleMap: Record<string, T>,
  defaultCycle: T
): T {
  if (!cycle) return defaultCycle;
  const normalized = cycle
    .trim()
    .toLowerCase()
    .replace(/[_\s-]+/g, " ");
  return cycleMap[normalized] ?? defaultCycle;
}
