import { aggregateCandidateVotes } from "../../../../utils/election/index.js";
import candidateResult from './candidateResult';
import calls from './calls';
const results = function results(data, options = {}) {
  const {
    id,
    results: resultsData = [],
    calls: callList,
    ...restData
  } = data;
  const {
    contestId = `contest:${id}`,
    formatId = d => `contest:${d.id}`,
    additionalContext = () => ({})
  } = options;
  const totalVotes = aggregateCandidateVotes(data);
  return {
    id: formatId(data),
    totalVotes,
    results: resultsData.map(result => candidateResult({
      result,
      contestId,
      totalVotes
    })),
    calls: callList && calls(callList),
    ...restData,
    ...additionalContext(data)
  };
};
export default results;