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

const proc = PROCEDURES.save_user_page

export enum LogActions {
  PageChange = 1,
  VideoChange = 2,
}

type Args = {
  actionType: LogActions,
  dateVisit: string,
  duration: number,
  matchId?: number,
  playerId?: number,
  playlistType?: number,
  sportType?: SportTypes,
  url: string,
}

export const logUserAction = ({
  actionType,
  dateVisit,
  duration,
  matchId,
  playerId,
  playlistType,
  sportType,
  url,
}: Args) => {
  const config = {
    body: {
      params: {
        _p_change_type: actionType,
        _p_date_visit: dateVisit,
        _p_duration: duration,
        _p_match_id: matchId,
        _p_player_id: playerId,
        _p_playlist_type: playlistType,
        _p_sport: sportType,
        _p_url: url,
      },
      proc,
    },
  }

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