/**
 * Extracts and parses the reward points (Lesepunkte) value from an order item's features.
 *
 * @param orderItem - An object containing a features property with key-value pairs
 * @returns The parsed numeric value of reward points, or undefined if not present
 *
 * @example
 * ```ts
 * const orderItem = { features: { praemie: '12.345' } };
 * const points = getOrderItemRewardFeature(orderItem); // returns 12345
 * ```
 */
export function getOrderItemRewardFeatureHelper(
  orderItem: { features?: { [key: string]: string } } | undefined,
): undefined | number {
  if (!orderItem || !orderItem.features) {
    return undefined;
  }

  // Return 12.345 as string needs to be converted to number. Remove . to avoid issues with different locales.
  const rewardFeature = orderItem.features['praemie'];

  return rewardFeature
    ? Number(rewardFeature.replace('.', '').replace(',', '.'))
    : undefined;
}
