import {
  RequestPermissionParams,
  RequestPermissionResponse,
} from '@shopify/shop-minis-platform/actions'

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

interface UseRequestPermissionsReturns {
  /**
   * Request native permissions from the user
   */
  requestPermission: (
    params: RequestPermissionParams
  ) => Promise<RequestPermissionResponse>
}

export const useRequestPermissions = (): UseRequestPermissionsReturns => {
  const {requestPermission} = useShopActions()

  return {
    requestPermission: useHandleAction(requestPermission),
  }
}
