import {
  AddToCartParams,
  BuyProductParams,
} from '@shopify/shop-minis-platform/actions'

import {useHandleAction} from '../../internal/useHandleAction'
import {useShopActions} from '../../internal/useShopActions'

interface UseShopCartActionsReturns {
  /**
   * Add a product to the cart
   */
  addToCart: (params: AddToCartParams) => Promise<void>
  /**
   * Buy a product directly
   */
  buyProduct: (params: BuyProductParams) => Promise<void>
}

export const useShopCartActions = (): UseShopCartActionsReturns => {
  const {addToCart, buyProduct} = useShopActions()

  return {
    addToCart: useHandleAction(addToCart),
    buyProduct: useHandleAction(buyProduct),
  }
}
