/**
 * Small env helpers.
 *
 * `process.env.X ?? fallback` does NOT fall back on empty strings — only on
 * undefined/null. That bites us when dotenv loads `KEY=` (blank value) from
 * `.env`. Use `envString` / `envNumber` to get safe fallbacks.
 */

export const envString = (value: string | undefined | null, fallback: string): string => {
  if (value === undefined || value === null) return fallback;
  return value.length > 0 ? value : fallback;
};

export const envNumber = (value: string | undefined | null, fallback: number): number => {
  if (value === undefined || value === null) return fallback;
  const trimmed = value.trim();
  if (trimmed.length === 0) return fallback;
  const parsed = Number(trimmed);
  return Number.isFinite(parsed) ? parsed : fallback;
};
