/**
 * Calculates the capacity based on the provided capacity values.
 * It returns the minimum of the two capacity values.
 * @param {Object} params - The parameters for the calculation
 * @param {number} params.capacityValue2 - The second capacity value
 * @param {number} params.capacityValue3 - The third capacity value
 * @return {number} The calculated capacity
 */
export const calculateCapacity = ({
  capacityValue2,
  capacityValue3,
}: {
  capacityValue2: number;
  capacityValue3: number;
}): number => {
  return capacityValue3 > capacityValue2 ? capacityValue2 : capacityValue3;
};

/**
 * Calculates the maximum capacity based on the provided capacity values.
 * It compares the values and returns the maximum capacity that is greater than or equal to the comparer
 * or the maximum of the capacity values.
 * @param {Object} params - The parameters for the calculation
 * @param {number} params.capacityValue2 - The second capacity value
 * @param {number} params.capacityValue3 - The third capacity value
 * @param {number} params.capacityValue4 - The fourth capacity value (optional)
 * @param {number} params.comparer - The value to compare against
 * @return {number} The maximum capacity calculated
 */
export const calculateMaxCapacity = ({
  capacityValue2 = 0,
  capacityValue3 = 0,
  capacityValue4 = 0,
  comparer,
}: {
  capacityValue2: number;
  capacityValue3: number;
  capacityValue4: number | undefined;
  comparer: number;
}): number => {
  let maxCapacity = 0;

  if (capacityValue4 < capacityValue2) {
    if (capacityValue4 > 0) {
      maxCapacity = capacityValue4;
    } else if (capacityValue3 > capacityValue2) {
      maxCapacity = capacityValue2;
    } else if (capacityValue3 > 0) {
      maxCapacity = capacityValue3;
    }
  } else {
    maxCapacity = capacityValue2;
  }

  return Math.max(comparer, maxCapacity);
};
