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

const proc = PROCEDURES.get_user_match_second

type Response = {
  _p_half: number | null,
  _p_second: number | null,
}

export type LastPlayPosition = {
  half: number,
  second: number,
}

export const getMatchLastWatchSeconds = async (
  sportType: SportTypes,
  matchId: number,
) => {
  const config = {
    body: {
      params: {
        _p_match_id: matchId,
        _p_sport: sportType,
      },
      proc,
    },
  }

  const response: Response = await callApi({
    config,
    url: DATA_URL,
  })

  return {
    half: response?._p_half ?? 0,
    second: response?._p_second ?? 0,
  }
}
