import { ExtensionHasNoMethodError } from './errors.esnext';
import { useApi } from './api.esnext';
import { useSubscription } from './subscription.esnext';

/**
 * Returns the order information that's available post-checkout.
 */
function useOrder() {
  const api = useApi();
  if ('order' in api) {
    return useSubscription(api.order);
  }
  throw new ExtensionHasNoMethodError('order', api.extension.target);
}

export { useOrder };
