import { AID, AttributeInfo } from '../attributes'; import { Catalog, Key, PID } from '../catalog'; import { ProductRecipe, OptionRecipe } from '../cookbook'; import { IRuleChecker } from '../rules'; import { IdGenerator } from '../utilities'; import { Cart, FindItemPredicate, ICartOps, ItemInstance, UID } from './interfaces'; /** * CartOps operates on Carts, ItemInstances, and attributes. Functionality * includes searching Carts and ItemInstances, modifying Carts and * ItemInstances, and creating new ItemInstances. */ export declare class CartOps implements ICartOps { attributeInfo: AttributeInfo; catalog: Catalog; ruleChecker: IRuleChecker; idGenerator: IdGenerator; constructor(attributeInfo: AttributeInfo, catalog: Catalog, ruleChecker: IRuleChecker); /** * Adds an item to the cart. * * @returnType a shallow copy of the cart with the item appended. */ addToCart(cart: Cart, item: ItemInstance): Cart; /** * Adds a child item to a parent. Does not verify that the option is legal * for the item. * * @returnType a shallow copy of the parent with the child appended. */ addToItem(parent: ItemInstance, child: ItemInstance): ItemInstance; addToItemWithReplacement(parent: ItemInstance, child: ItemInstance, combineQuantities: boolean): ItemInstance; /** * Items with a Key matching the Key that is passed in are returned in the * order they were added to the cart. * * @useCase find all instances of a specific drink like a `large iced` * `latte`. * * @returnType an iterable of ItemInstances in the cart that correspond to a * particular Key. */ findByKey(cart: Cart, key: Key): IterableIterator; /** * Items with a Key matching the regular expression Key that is passed in * are returned in the order they were added to the cart. * * @useCase find all instances of a specific drink like a `large iced` * `latte`. * * @returnType an iterable of ItemInstances in the cart that correspond to a * particular Key. */ findByKeyRegex(cart: Cart, key: Key): IterableIterator; /** * Items with a PID matching the PID that is passed in are returned in the * order they were added to the cart. * * @useCase want to find all lattes, regardless of attributes. Searching * with the PID for 'latte' might return ItemInstances for a 'medium iced * latte' and a 'small hot latte'. * * @returnType an iterable of ItemInstances in the cart that correspond to a * particular PID (instance of generic entity) */ findByPID(cart: Cart, pid: PID): IterableIterator; /** * Items with a child that have a Key matching the Key that is passed in are * returned in the order they were added to the cart. * * @returnType an iterable of ItemInstances that contain a child with a * particular Key (instance of specific entity). */ findByChildKey(cart: Cart, key: Key): IterableIterator; findByChildPID(cart: Cart, pid: PID): IterableIterator; findCompatibleParent(cart: Cart, childKey: Key): IterableIterator; findInCart(cart: Cart, predicate: FindItemPredicate): IterableIterator; findInItemArray(items: ItemInstance[], predicate: FindItemPredicate): IterableIterator; replaceInCart(cart: Cart, item: ItemInstance): Cart; private replaceInItemArray; removeFromCart(cart: Cart, uid: UID): Cart; private removeFromItemArray; /** * Creates an ItemInstance representing a SpecificEntity. * The Key is determined by the PID and AIDs that are passed in. * This method generates a unique value for the ItemInstance's UID field. * * @param {PID} pid A GenericEntity product id. * @param aids An iterator of attribute ids used to configure the * GenericEntity into a SpecificEntity. * @param children The child entities (options) * @param generateRegexKey If true, the ItemInstance key will be a regex * with `"\d+"` in coordinate fields that were not specified by attributes * in `aids`. * * @returnType a newly generated ItemInstance with a unique UID. */ createItem(quantity: number, pid: PID, aids: IterableIterator, children: IterableIterator, generateRegexKey: boolean): ItemInstance; changeItemAttributes(item: ItemInstance, newAIDs: IterableIterator): ItemInstance; changeItemPID(item: ItemInstance, newPID: PID): ItemInstance; createItemsFromProductRecipe(recipe: ProductRecipe): ItemInstance[]; createItemsFromOptionRecipe(recipe: OptionRecipe): ItemInstance[]; }