import formatNumber from '../formatNumber';
import aggregateCandidateVotes from '../aggregateCandidateVotes';
import aggregateCandidateVotePercents from '../aggregateCandidateVotePercents';

/**
 * Format an aggregation of candidate votes in a particular contest.
 *
 * @param {ContestSummaryResults} summary
 * @param {CandidateId[]} candidateIds
 * @param {Object} [options]
 *   Additional configuration:
 *   - `format` type `'number'|'percent'` default `'number'`
 *   - `locale` type `string`
 * @returns {string}
 */
function getFormattedAggregateCandidateVotes(summary, candidateIds, options = {}) {
  const {
    format = 'number',
    ...restOpts
  } = options;
  const aggregation = format === 'percent' ? aggregateCandidateVotePercents(summary, candidateIds) : aggregateCandidateVotes(summary, candidateIds);
  return formatNumber(aggregation, {
    format,
    ...restOpts
  });
}
export default getFormattedAggregateCandidateVotes;