import type { Discount, Measurement, Image } from "./common"; export type SelectedOption = { id?: string; name: string; value: string; }; export type LineItem = { id: string; variantId: string; productId: string; name: string; quantity: number; discounts: Discount[]; path: string; variant: ProductVariant; options?: SelectedOption[]; }; export type ProductVariant = { id: string; sku: string; name: string; requiresShipping: boolean; price: number; listPrice: number; image?: Image; isInStock?: boolean; availableForSale?: boolean; weight?: Measurement; height?: Measurement; width?: Measurement; depth?: Measurement; }; export type Cart = { id: string; customerId?: string; email?: string; createdAt: string; currency: { code: string; }; taxesIncluded: boolean; lineItems: LineItem[]; lineItemsSubtotalPrice: number; subtotalPrice: number; totalPrice: number; discounts?: Discount[]; }; /** * Base cart item body used for cart mutations */ export type CartItemBody = { variantId: string; productId?: string; quantity?: number; }; /** * Hooks schema */ export type CartTypes = { cart?: Cart; item: LineItem; itemBody: CartItemBody; }; export type CartHooks = { getCart: GetCartHook; addItem: AddItemHook; updateItem: UpdateItemHook; removeItem: RemoveItemHook; }; export type GetCartHook = { data: T["cart"] | null; input: {}; fetcherInput: { cartId?: string; }; swrState: { isEmpty: boolean; }; }; export type AddItemHook = { data: T["cart"]; input?: T["itemBody"]; fetcherInput: T["itemBody"]; body: { item: T["itemBody"]; }; actionInput: T["itemBody"]; }; export type UpdateItemHook = { data: T["cart"] | null; input: { item?: T["item"]; wait?: number; }; fetcherInput: { itemId: string; item: Partial; }; body: { itemId: string; item: Partial; }; actionInput: Partial & { id: string; }; }; export type RemoveItemHook = { data: T["cart"] | null; input: { item?: T["item"]; }; fetcherInput: { itemId: string; }; body: { itemId: string; }; actionInput: { id: string; }; }; /** * API Schema */ export type CartSchema = { endpoint: { options: {}; handlers: CartHandlers; }; }; export type CartHandlers = { getCart: GetCartHandler; addItem: AddItemHandler; updateItem: UpdateItemHandler; removeItem: RemoveItemHandler; }; export type GetCartHandler = GetCartHook & { body: { cartId?: string; }; }; export type AddItemHandler = AddItemHook & { body: { cartId: string; }; }; export type UpdateItemHandler = UpdateItemHook & { data: T["cart"]; body: { cartId: string; }; }; export type RemoveItemHandler = RemoveItemHook & { body: { cartId: string; }; };