// Cart Item (node)
export interface CartItem {
  id: string;
  cartId: string;
  productId: string;
  name: string;
  price: number;
  baseImage: string | null;
  sku: string;
  quantity: number;
  type: string;
  productUrlKey: string;
  canChangeQty: boolean;
}

// GraphQL Edge wrapper
export interface CartItemEdge {
  node: CartItem;
}

// Items connection
export interface CartItemsConnection {
  edges: CartItemEdge[];
} 

export interface CartAddress{
  id: string;
  firstName: string;
  lastName: string;
  email: string;
  address: string;
  city: string;
  state: string;
  country: string;
  postcode: string;
  phone: string;
}
// CartDetail
export interface CartDetail {
  id: string;
  appliedTaxes: Record<string, string>;
  itemsQty: number; //Total quantity of all items
  isGuest: boolean;
  itemsCount: number;
  items: CartItemsConnection;
  subtotal: number; // Subtotal before discounts and taxes
  subTotalInclTax: number;
  // baseSubtotal: number;
  discountAmount: number;
  // baseDiscountAmount: number;
  taxAmount: number;
  taxTotal: number;
  shippingAmount: number;
  shippingAmountInclTax: number;
  grandTotal: number;

  formattedSubtotal: string;
  formattedSubTotalInclTax: string;
  formattedDiscountAmount: string;
  formattedTaxAmount: string;
  formattedTaxTotal: string;
  formattedShippingAmount: string;
  formattedShippingAmountInclTax: string;
  formattedGrandTotal: string;
  couponCode: string | null;
  
  selectedShippingRate: string | null;
  selectedShippingRateTitle: string | null;
  paymentMethod: string | null;
  paymentMethodTitle: string | null;

  haveStockableItems: boolean;
  billingAddress: CartAddress | null;
  shippingAddress: CartAddress | null;
}

// createReadCart payload
export interface CreateReadCart {
  readCart: CartDetail;
}

// Mutation response data
export interface GetCartItemData {
  createReadCart: CreateReadCart;
}

export interface ReadCartOperation {
  data: GetCartItemData;
}

// Add Product In Cart
export interface AddProductInCart extends CartDetail {
  cartToken: string;
  sessionToken: string;
  success: boolean;
  message: string;
}

export interface CreateAddProductInCart {
  addProductInCart: AddProductInCart;
}

export interface AddToCartData {
  createAddProductInCart: CreateAddProductInCart;
}

export interface AddToCartVariables {
  cartId?: number | null;
  productId: number;
  quantity: number;
}


// Guest Cart Token
export interface CartToken {
  id: string;
  cartToken: string;
  customerId: string | null;
  success: boolean;
  message: string;
  sessionToken: string;
  isGuest: boolean;
}

export interface CreateCartTokenPayload {
  cartToken: CartToken;
}

export interface CreateCartTokenData {
  createCartToken: CreateCartTokenPayload;
}
export type CreateCartTokenVariables = void;

export interface CreateCartTokenOperation {
  data: CreateCartTokenData;
  variables: CreateCartTokenVariables;
}

// Merge Cart
export interface CreateMergeCartPayload {
  mergeCart: CartDetail;
}
export interface CreateMergeCartData {
  createMergeCart: CreateMergeCartPayload;
}
export interface CreateMergeCartVariables {
  cartId: number;
}
export interface CreateMergeCartOperation {
  data: CreateMergeCartData;
  variables: CreateMergeCartVariables;
}

// Remove Cart Item
export interface CreateRemoveCartItemPayload {
  removeCartItem: CartDetail;
}

export interface RemoveCartItemData {
  createRemoveCartItem: CreateRemoveCartItemPayload;
}

export interface RemoveCartItemVariables {
  cartItemId: number;
}

// Update Cart Item
export interface CreateUpdateCartItemPayload {
  updateCartItem: CartDetail;
}
export interface UpdateCartItemData {
  createUpdateCartItem: CreateUpdateCartItemPayload;
}
export interface UpdateCartItemVariables {
  cartItemId: number;
  quantity: number;
}