/**
 * Wagon fraction one container occupies, derived from its size: 40ft = 1 wagon,
 * 20ft = 0.5 (two per wagon). Unknown size reads as a whole wagon so counts
 * never under-book.
 */
export function wagonsPerUnitForSize(sizeFt?: number | null): number {
  const size = Number(sizeFt);
  if (!Number.isFinite(size) || size <= 0) return 1;
  return size >= 40 ? 1 : 0.5;
}

/** Containers that fit on one wagon for a given container size (inverse of the wagon fraction). */
export function containersPerWagonForSize(sizeFt?: number | null): number {
  return Math.max(1, Math.round(1 / wagonsPerUnitForSize(sizeFt)));
}
