import {
  DATA_URL,
  PROCEDURES,
  ProfileTypes,
} from 'config'

import { callApi } from 'helpers'

const proc = PROCEDURES.landing_get_match_info

type Team = {
  name_eng: string,
  name_rus: string,
}

export type UnauthenticatedMatch = {
  date?: string,
  live?: boolean,
  team1?: Team,
  team2?: Team,
  tournament: {
    name_eng: string,
    name_rus: string,
  },
} | null

export const getUnauthenticatedMatch = (
  sportId: number,
  matchId: number,
  profileType?: ProfileTypes,
)
: Promise<UnauthenticatedMatch> => {
  const config = {
    body: {
      params: {
        _p_match_id: profileType === ProfileTypes.MATCHES
          ? matchId
          : null,
        _p_sport: sportId,
        _p_tournament_id: profileType === ProfileTypes.TOURNAMENTS
          ? matchId
          : null,
      },
      proc,
    },
  }

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