import {
  getOrderTypeFeature,
  ShoppingCartItem,
} from '@isa/checkout/data-access';

/**
 * Creates a unique key for an item based on EAN, targetBranchId, and orderItemType.
 * Items are only considered identical if all three match.
 */
export const getItemKey = (item: ShoppingCartItem): string => {
  const ean = item.product.ean ?? 'no-ean';
  const targetBranchId =
    item.destination?.data?.targetBranch?.id ?? 'no-target-branch-id';
  const orderType = getOrderTypeFeature(item.features) ?? 'no-orderType';
  return `${ean}|${targetBranchId}|${orderType}`;
};
