import { API_ROOT, PAGES } from 'config'

import { callApi } from 'helpers'

import type { SubscriptionResponse } from 'requests/getSubscriptions'

type Props = {
  action: 'one_payment' | 'create_subscription',
  item: SubscriptionResponse,
  product_name: string,
}

export const getBrazilPaymentUrl = async ({
  action,
  item,
  product_name,
}: Props) => {
  const config = {
    body: {
      action,
      data: {
        item: { ...item, product_name },
        url_return: `${window.location.origin}${PAGES.thanksForSubscribe}`,
      },
      service: 'pag_brasil',
    },
  }

  return callApi({
    config,
    url: `${API_ROOT}/account/payments`,
  })
}
