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

const proc = PROCEDURES.lst_c_country

export type Country = {
  id: number,
  iso_3166_1_alpha_2: string,
  iso_3166_1_alpha_3: string,
  name_eng: string,
  name_rus: string,
  phone_code: string | null,
}

export type Countries = Array<Country>

export const getCountries = (): Promise<Countries> => {
  const config = {
    body: {
      params: {},
      proc,
    },
  }

  return callApi({
    config,
    url: DATA_URL,
  }).then(getResponseData(proc))
}
