/** Mínimo de piezas a cobrar (alineado con config/lavanderia.php). */
export const LAUNDRY_PIECE_MIN_BILL_QTY = 3;

/**
 * Cantidad facturable a partir de la cantidad real registrada.
 * @param {number|string|null|undefined} raw
 * @param {number} [minQty]
 * @returns {number}
 */
export function billingPieceQuantity(raw, minQty = LAUNDRY_PIECE_MIN_BILL_QTY) {
  const n = Number(raw);
  const min = Math.max(1, Number(minQty) || LAUNDRY_PIECE_MIN_BILL_QTY);
  if (!Number.isFinite(n) || n <= 0) {
    return 0;
  }

  return Math.max(min, Math.round(n));
}
