/**
 * Helper to reformat contest calls into the structure required for contest
 * summaries. Exported for testing purposes.
 */
const formattedContestCallEventsFromCalls = (contestId, callList) => {
  const callsByParty = new Map();
  const callsByCandidate = new Map();
  const calls = callList.filter(call => {
    if (call.contestId !== contestId) return false;
    if (call.subjectType === 'candidate') {
      callsByCandidate.set(call.subjectId, [...(callsByCandidate.get(call.subjectId) || []), call]);
    }
    if (call.subjectType === 'party') {
      callsByParty.set(call.subjectId, [...(callsByParty.get(call.subjectId) || []), call]);
    }
    return true;
  });
  return {
    calls,
    callsByParty: Object.fromEntries(callsByParty),
    callsByCandidate: Object.fromEntries(callsByCandidate)
  };
};
export default formattedContestCallEventsFromCalls;