import { VIEWS_API } from 'config'

import { callApi } from 'helpers'

type Props = {
  matchDate?: string,
  matchId: number,
  matchSecond: number,
  seasonId?: number,
  sportType: number,
  teamFirst?: number,
  teamSecond?: number,
  tournamentId?: number,
}

export const VIEW_INTERVAL_MS = 5000

export const saveMatchStats = ({
  matchDate,
  matchId,
  matchSecond,
  seasonId,
  sportType,
  teamFirst,
  teamSecond,
  tournamentId,
}: Props) => {
  const url = `${VIEWS_API}/v2/user/view`

  const config = {
    body: {
      duration: VIEW_INTERVAL_MS / 1000,
      match_date: matchDate,
      match_id: matchId,
      season: seasonId,
      second: matchSecond,
      sport_id: sportType,
      team1: teamFirst,
      team2: teamSecond,
      tournament: tournamentId,
    },
  }

  return callApi({ config, url })
}
