// Import live-grouper
import { EventStateData, GrouperAlgorithm } from 'dce-live-grouper';

// Import shared helper
import genOccurrenceId from '../../../shared/helpers/genOccurrenceId';

// Import shared constants
import TTM_PATH_PREFIX from '../../../shared/constants/TTM_PATH_PREFIX';

// Import shared types
import OccurrenceBasicInfo from '../../../shared/types/OccurrenceBasicInfo';
import MMDDYY from '../../../shared/types/MMDDYY';

// Import types
import VisitServerEndpoint from '../../../types/VisitServerEndpoint';

/**
 * Call the backend to retrieve old groups and algorithm choices.
 * @author Benedikt Arnarsson
 * @param occInfo the basic info for the current occurrence.
 * @param mmddyy the date of the event we are retrieving info for.
 */
const getOldEventInfo = async (
  visitServerEndpoint: VisitServerEndpoint,
  occInfo: OccurrenceBasicInfo,
  mmddyy: MMDDYY,
): Promise<EventStateData> => {
  const {
    courseId,
    ihid,
  } = occInfo;

  const occId = genOccurrenceId({
    courseId,
    ihid,
    ...mmddyy,
  });

  const eventId = occId.replace(`${courseId}-`, "");

  return visitServerEndpoint({
    path: `${TTM_PATH_PREFIX}/grouper/event`,
    params: {
      courseId,
      eventId,
    },
  });
};

export default getOldEventInfo;
