import {
  FavoriteParams,
  UnfavoriteParams,
} from '@shopify/shop-minis-platform/actions'

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

interface UseSavedProductsActionsReturns {
  /**
   * Save a product.
   */
  saveProduct: (params: FavoriteParams) => Promise<void>
  /**
   * Unsave a product.
   */
  unsaveProduct: (params: UnfavoriteParams) => Promise<void>
}

export const useSavedProductsActions = (): UseSavedProductsActionsReturns => {
  const {favorite, unfavorite} = useShopActions()

  return {
    saveProduct: useHandleAction(favorite),
    unsaveProduct: useHandleAction(unfavorite),
  }
}
