import type { Match } from 'requests'

import { getMatchAccess, MatchAccess } from '..'

type Args = {
  access?: boolean,
  calc?: boolean,
  date?: string,
  has_video?: boolean,
  live?: boolean,
  storage?: boolean,
  sub?: boolean,
}

const createMatch = (args: Args) => ({
  ...args,
} as Match)

const user = undefined

it('equals to no country access type', () => {
  const match = createMatch({
    access: false,
    sub: false,
  })

  expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser)
})

it('equals to  redirect type', () => {
  const match = createMatch({
    access: true,
    calc: false,
    date: '2020-01-01 00:00:00',
    has_video: true,
    sub: true,
  })

  expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser)
})

it('equals to  can buy type', () => {
  const match = createMatch({
    access: true,
    sub: false,
  })

  expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser)
})

it('equals to view match popup type', () => {
  let match = createMatch({
    access: true,
    date: '2020-01-01 00:00:00',
    live: true,
    sub: true,
  })

  expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser)

  match = createMatch({
    access: true,
    calc: true,
    date: '2022-01-01 00:00:00',
    has_video: true,
    live: false,
    sub: true,
  })

  expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser)

  match = createMatch({
    access: true,
    calc: true,
    date: '2040-01-01 00:00:00',
    has_video: false,
    live: true,
    storage: true,
    sub: true,
  })

  expect(getMatchAccess(match, user)).toBe(MatchAccess.NoAccess)
})
