import type { Match } from 'requests'

export enum MatchAccess {
  CanBuyMatch = 'CanBuyMatch',
  NoAccess = 'NoAccess',
  NoCountryAccess = 'NoCountryAccess',
  RedirectToProfile = 'RedirectToProfile',
  ViewMatchPopup = 'ViewMatchPopup',
}

export const getMatchAccess = ({
  access,
  calc,
  date,
  has_video,
  live,
  storage,
  sub,
}: Match) => {
  switch (true) {
    case !sub:
      return MatchAccess.CanBuyMatch
    case !access:
      return MatchAccess.NoCountryAccess
      // проверка времени матча - 10минут
    case ((new Date(Date.parse(date.toString()) - 10 * 60 * 1000) < new Date()) && !live):
      return MatchAccess.RedirectToProfile
    case live:
      return MatchAccess.ViewMatchPopup
    default:
      return MatchAccess.NoAccess
  }
}
