import {
  AddProductListParams,
  RemoveProductListParams,
  RenameProductListParams,
  AddProductListItemParams,
  RemoveProductListItemParams,
} from '@shopify/shop-minis-platform/actions'

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

interface UseProductListActionsReturns {
  /**
   * Add a product list
   */
  addProductList: (params: AddProductListParams) => Promise<ProductList>
  /**
   * Remove a product list
   */
  removeProductList: (params: RemoveProductListParams) => Promise<void>
  /**
   * Rename a product list
   */
  renameProductList: (params: RenameProductListParams) => Promise<ProductList>
  /**
   * Add a product to a product list
   */
  addProductListItem: (params: AddProductListItemParams) => Promise<void>
  /**
   * Remove a product from a product list
   */
  removeProductListItem: (params: RemoveProductListItemParams) => Promise<void>
}

export const useProductListActions = (): UseProductListActionsReturns => {
  const {
    addProductList,
    removeProductList,
    renameProductList,
    addProductListItem,
    removeProductListItem,
  } = useShopActions()

  return {
    addProductList: useHandleAction(addProductList),
    removeProductList: useHandleAction(removeProductList),
    renameProductList: useHandleAction(renameProductList),
    addProductListItem: useHandleAction(addProductListItem),
    removeProductListItem: useHandleAction(removeProductListItem),
  }
}
