import { RewardSelectionItem } from '@isa/checkout/data-access';

export const calculateLoyaltyPointsValue = (
  rewardSelectionItem: RewardSelectionItem,
): number => {
  const itemLoyaltyPoints = rewardSelectionItem.item?.loyalty?.value;
  const catalogLoyaltyPoints = rewardSelectionItem?.catalogRewardPoints;

  if (itemLoyaltyPoints != null && itemLoyaltyPoints !== 0) {
    return itemLoyaltyPoints;
  }

  if (catalogLoyaltyPoints != null && catalogLoyaltyPoints !== 0) {
    return catalogLoyaltyPoints;
  }

  return 0;
};
