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

const proc = PROCEDURES.get_user_favorites

type ObjectWithName = {
  id: number,
  name_eng: string,
  name_rus: string,
}

type Info = {
  country?: ObjectWithName,
  date?: string,
  firstname_eng?: string,
  firstname_rus?: string,
  lastname_eng?: string,
  lastname_rus?: string,
  name_eng?: string,
  name_rus?: string,
  nickname_eng?: string,
  nickname_rus?: string,
  short_name_eng?: string,
  short_name_rus?: string,
  team?: ObjectWithName,
  team1?: ObjectWithName,
  team2?: ObjectWithName,
}

export type UserFavorite = {
  id: number,
  info: Info,
  sport: SportTypes,
  type: ProfileTypes,
}

export type UserFavorites = Array<UserFavorite>

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

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