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

const proc = PROCEDURES.get_user_info

export type UserInfo = {
  address_line1: string | null,
  address_line2: string | null,
  city: string | null,
  cityId: number | null,
  country?: {
    id: number,
    name_eng: string,
    name_rus: string,
  },
  email: string,
  firstname: string | null,
  has_subscription: boolean,
  is_unsubscribed: boolean | null,
  language: {
    id: number | null,
    iso: string | null,
    name_en: string | null,
    name_ru: string | null,
  },
  lastname: string | null,
  password: string | null,
  phone: string | null,
  postal_code: number | null,
  region: string | null,
}

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

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