import { Event, EventType } from "../../../event/core/event"; /** * Product in a order event. * * @export * @interface OrderProduct */ export interface OrderProduct { product: string; price: number; quantity: number; } /** * Page Confirmation Event. * * Should be used whenever the user completes an order. * Order ID is mandatory. * * @export * @class PageConfirmationEvent * @extends {Event} */ export class PageConfirmationEvent extends Event { public products: OrderProduct[] = []; public type: EventType = EventType.PageConfirmation; /** * Creates an instance of PageConfirmationEvent. * * @param {string} order * @param {string} locale * @param {string} channel * @param {string} session * @param {string} anonymous * @memberof PageConfirmationEvent */ constructor( public order: string, public locale?: string, public channel?: string, session?: string, anonymous?: string, ) { super(session, anonymous); } /** * Add a product to this order event. * * @param {string} product Product's ID. * @param {number} price Product's current price. * @param {number} [quantity=1] Quantity bought. * @return {PageConfirmationEvent} * @memberof PageConfirmationEvent */ public withProduct(product: string, price: number, quantity = 1): PageConfirmationEvent { this.products.push({ product, price, quantity }); return this; } /** * Add a series of products to this order event. * * @param {OrderProduct[]} products All the products to be added. * @return {PageConfirmationEvent} * @memberof PageConfirmationEvent */ public withProducts(products: OrderProduct[]): PageConfirmationEvent { this.products.push(...products); return this; } }