import { DATA_URL } from 'config'
import { callApi } from 'helpers'

import type { MatchesResponse, MatchesBySection } from './types'

type Config = {
  body: {
    proc: string,
  },
}

export const requestMatches = async (config: Config): Promise<MatchesBySection> => {
  const {
    is_video_sections,
    show,
    video_content: data,
  }: MatchesResponse = await callApi({
    config,
    url: DATA_URL,
  })

  return {
    broadcast: data.broadcast || [],
    features: data.features || [],
    hasNextPage: Boolean(show),
    highlights: data.highlights || [],
    isVideoSections: Boolean(is_video_sections),
  }
}
