import { DATA_URL, PROCEDURES } from 'config'
import { callApi } from 'helpers'

const proc = PROCEDURES.get_user_subscribes

export type Subscribe = {
  access_to: string,
  c_payment_service: number,
  c_subscription_option: number,
  card: string,
  currency_id: number,
  dt_next_billing: string | null,
  is_access: boolean,
  is_active: boolean,
  is_gpay?: boolean,
  iso: string,
  lexic: number,
  lexic1: number,
  lexic2: number,
  name: string,
  option_name: string,
  option_sys_name: string,
  payment_type: string,
  price: number,
  purchase_type: string,
  sub_external_id: number | null,
  sub_id: number | null,
  sub_info: Array<Team>,
  ts_payment: string,
}

type Team = {
  id: number,
  name_en: string,
  name_ru: string,
}

export type Subscribes = Array<Subscribe>

export const getUserSubscribes = (
  _p_email: string,
)
: Promise<Subscribes> => {
  const config = {
    body: {
      params: {
        _p_email,
      },
      proc,
    },
  }

  return callApi({
    config,
    url: DATA_URL,
  })
}
