import { DisplayOrderItemSubset } from '@isa/oms/data-access';

/**
 * Checks if any of the subset items has a LOYALTY_COLLECT_COMMAND action
 * @param items - Array of DisplayOrderItemSubset to check
 * @returns true if at least one item has a LOYALTY_COLLECT_COMMAND action
 */
export const hasLoyaltyCollectCommand = (
  items?: DisplayOrderItemSubset[],
): boolean => {
  const firstItem = items?.find((_) => true);
  return (
    firstItem?.actions?.some((action) =>
      action?.command?.includes('LOYALTY_COLLECT_COMMAND'),
    ) ?? false
  );
};
