/**
 * Target stock after remission.
 *
 * - If `remainingQuantityInStock` is set (non-zero), returns that value.
 * - Otherwise, calculates as `availableStock - stockToRemit`.
 * - Returns 0 if the result is negative.
 *
 * @remarks
 * Depends on `stockToRemit` for calculation.
 * Represents the expected stock after the remission process.
 */
export const calculateTargetStock = ({
  availableStock,
  stockToRemit,
  remainingQuantityInStock,
}: {
  availableStock: number;
  stockToRemit?: number;
  remainingQuantityInStock?: number;
}): number => {
  if (!remainingQuantityInStock) {
    const targetStock = availableStock - (stockToRemit ?? 0);
    return targetStock < 0 ? 0 : targetStock;
  }

  return remainingQuantityInStock;
};
