diff --git a/src/model/cart.ts b/src/model/cart.ts index 5da7584..da4a591 100644 --- a/src/model/cart.ts +++ b/src/model/cart.ts @@ -33,4 +33,125 @@ export interface Discount { incomeMore: number; toTime: number; toCapacity: number; +} + +// New types from snippet +export namespace Cart { + type ServiceType = + | "templategen" + | "squiz" + | "dwarfener"; + + type PrivilegeType = + | "unlim" + | "gencount" + | "activequiz" + | "abcount" + | "extended"; + + export interface Privilege { + serviceKey: ServiceType; + name: PrivilegeType; + privilegeId: string; + description: string; + type: "day" | "count"; + price: number; + } + + export type Discount = { + _id: string; + name: string; + description: string; + /** + * Этап применения скидки + */ + layer: number; + } & ({ + conditionType: "purchasesAmount"; + condition: { + purchasesAmount: number; + }; + /** + * Множитель, на который умножается сумма при применении скидки + */ + factor: number; + } | { + conditionType: "cartPurchasesAmount"; + condition: { + cartPurchasesAmount: number; + }; + /** + * Множитель, на который умножается сумма при применении скидки + */ + factor: number; + } | { + conditionType: "privilege"; + condition: { + privilege: { + id: string; + /** + * Скидка применяется, если значение больше или равно этому значению + */ + value: number; + }; + }; + target: { + products: Array<{ + productId: string; + /** + * Множитель, на который умножается сумма при применении скидки + */ + factor: number; + }>; + }; + } | { + conditionType: "service"; + condition: { + service: { + id: ServiceType; + /** + * Скидка применяется, если значение больше или равно этому значению + */ + value: number; + }; + }; + target: { + service: ServiceType; + /** + * Множитель, на который умножается сумма при применении скидки + */ + factor: number; + }; + } | { + conditionType: "userType"; + condition: { + userType: string; + }; + target: { + IsAllProducts: boolean; + /** + * Множитель, на который умножается сумма при применении скидки + */ + factor: number; + }; + overwhelm: boolean; + } | { + conditionType: "user"; + condition: { + coupon: string; + user: string; + }; + target: { + products: Array<{ + productId: string; + /** + * Множитель, на который умножается сумма при применении скидки + */ + factor: number; + }>; + }; + overwhelm: boolean; + }); + + export type DiscountConditionType = Discount["conditionType"]; } \ No newline at end of file