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

const proc = PROCEDURES.get_user_payments

type Payment = {
  card: string,
  currency: string,
  currency_id: number,
  id: number,
  payment_service: string,
  payment_type: string,
  price: number,
  purchase_type: string,
  sub_id: number,
  sub_info: MatchOfOneTeam | MatchOne | Tournaments,
  sub_name: string,
  sub_option: string,
  ts_payment: string,
}

type MatchOfOneTeam = {
  country_en: string,
  country_id: number,
  country_ru: string,
  sport_id: number,
  team_en: string,
  team_id: number,
  team_ru: string,
}

type MatchOne = {
  country_en: string,
  country_id: number,
  country_ru: string,
  date: string,
  id: number,
  name: string,
  season: string,
  sport_id: number,
  tournament: string,
}

type Tournament = {
  id: number,
  name_en: string,
  name_ru: string,
  sport_id: number,
}

type Tournaments = Array<Tournament>
export type PaymentsList = Array<Payment>

export const getUserListPayments = (
  timezoneOffset: number,
  _p_email: string,
)
: Promise<PaymentsList> => {
  const config = {
    body: {
      params: {
        _p_email,
        _p_gmt: timezoneOffset,
      },
      proc,
    },
  }

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