// eslint-disable-next-line import/prefer-default-export
export const getEventDetailsData = async (eventId, lang) => {
  const res = await fetch(
    `${process.env.SPORTS_API}sports-api/events/${eventId}${lang ? `?lang=${lang}` : ''}`
  );
  const data = res.status === 200 && (await res.json());
  return data;
};

export const getStatisticsData = async (eventId) => {
  const res = await fetch(`${process.env.SPORTS_API}sports-api/events/${eventId}/statistics`);
  const data = res.status === 200 && (await res.json());
  return data;
};

export const getOddsData = async (eventId, operatorList) => {
  const operators = operatorList
    ? operatorList.map((x) => x.short_name).join(',')
    : 'bet365,unibet,betsson,betinia,campobet,leovegas,paf,casinostugan,bethard,scandibet,noaccountbet,nordicbet,hajper,mrgreen,comeon,10bet,betway,888sport,coolbet,betfair,casumo,luckycasino,betsafe,svenska_spel,speedybet,bwin,snabbare,expekt,williamhill,pixelbet,fastbet,gutsxpress';

  const res = await fetch(
    `${process.env.SPORTS_API}odds/events/${eventId}/1x2?providers=${operators.split(',')}`
  );

  const data = res.status === 200 && (await res.json());
  return data;
};

export const getIncidentsData = async (eventId, lang) => {
  const res = await fetch(
    `${process.env.SPORTS_API}sports-api/events/${eventId}/incidents${lang ? `?lang=${lang}` : ''}`
  );
  const data = res.status === 200 && (await res.json());
  return data;
};

export const getLineUpsData = async (eventId, lang) => {
  const res = await fetch(
    `${process.env.SPORTS_API}sports-api/events/${eventId}/lineups${lang ? `?lang=${lang}` : ''}`
  );
  const data = res.status === 200 && (await res.json());
  return data;
};

export const getHead2HeadsData = async (eventId, lang) => {
  const res = await fetch(
    `${process.env.SPORTS_API}sports-api/events/${eventId}/head2head${lang ? `?lang=${lang}` : ''}`
  );
  const data = res.status === 200 && (await res.json());
  return data;
};

export const getStandingsData = async (tournamentStage, lang) => {
  const res = await fetch(
    `${process.env.SPORTS_API}sports-api/tournament-stages/${tournamentStage}/standings${
      lang ? `?lang=${lang}` : ''
    }`
  );
  const data = tournamentStage ? res.status === 200 && (await res.json()) : null;
  return data;
};

export const getRoundsData = async (tournamentStage, lang) => {
  const res = await fetch(
    `${process.env.SPORTS_API}sports-api/tournament-stages/${tournamentStage}/rounds${
      lang ? `?lang=${lang}` : ''
    }`
  );
  const data = tournamentStage ? res.status === 200 && (await res.json()) : null;
  return data;
};

export const getScheduleData = async (tournamentStage, round, lang) => {
  const res = await fetch(
    `${
      process.env.SPORTS_API
    }sports-api/tournament-stages/${tournamentStage}/schedules?round=${round}${
      lang ? `&lang=${lang}` : ''
    }`
  );
  const data = tournamentStage ? res.status === 200 && (await res.json()) : null;
  return data;
};
