import {
  DATA_URL,
  PROCEDURES,
} from 'config'

import { callApi } from 'helpers'

const proc = PROCEDURES.get_match_info

export type Team = {
  abbrev_eng: string,
  abbrev_rus: string,
  id: number,
  name_eng: string,
  name_rus: string,
  score: number,
}

export type MatchInfo = {
  calc: boolean,
  country_id: number,
  date: string,
  has_video: boolean,
  live: boolean,
  storage: boolean,
  sub: boolean,
  team1: Team,
  team2: Team,
  tournament: {
    id: number,
    name_eng: string,
    name_rus: string,
  },
} | null

export const getMatchInfo = (sportId: number, matchId: number)
: Promise<MatchInfo> => {
  const config = {
    body: {
      params: {
        _p_match_id: matchId,
        _p_sport: sportId,
      },
      proc,
    },
  }

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