import {
  DATA_URL,
  PROCEDURES,
} from 'config'

import { callApi } from 'helpers'

const proc = PROCEDURES.get_team_info

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

export type TeamInfo = {
  country: NameObject,
  header_image: string | null,
  id: number,
  is_favorite: boolean,
  name_eng: string,
  name_rus: string,
  short_name_eng: string,
  short_name_rus: string,
  tournament: NameObject,
} | null

export const getTeamInfo = (sportId: number, teamId: number)
: Promise<TeamInfo> => {
  const config = {
    body: {
      params: {
        _p_sport: sportId,
        _p_team_id: teamId,
      },
      proc,
    },
  }

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