import { PRESIDENT, SENATE, GOVERNOR, HOUSE, LT_GOVERNOR, ATTORNEY_GENERAL, SEC_STATE } from './contests';
import senContestName from './senContestName';
import cdContestName from './cdContestName';
import stateAttyGenContestName from './stateAttyGenContestName';
import stateSecOfStateContestName from './stateSecOfStateContestName';
import govContestName from './govContestName';
import stateLtGovContestName from './stateLtGovContestName';
import presContestName from './presContestName';
const formatters = {
  [PRESIDENT]: presContestName,
  [SENATE]: senContestName,
  [GOVERNOR]: govContestName,
  [HOUSE]: cdContestName,
  [LT_GOVERNOR]: stateLtGovContestName,
  [ATTORNEY_GENERAL]: stateAttyGenContestName,
  [SEC_STATE]: stateSecOfStateContestName
};

/**
 * Get a contest's name in a particular format from its metadata.
 *
 * @param {ContestMetadata} contest
 *   The metadata of the contest for which you want the name. If no metadata is
 *   provided or if the metadata doesn't contain the appropriate name
 *   information for the requested format, this function returns `undefined`.
 * @param {Object} [options]
 *   Additional configuration options:
 *   - `format`: The format of the name (either `tiny`, `short`, `medium`,
 *     `long`, and `no-state`, the default being `long`)
 * @returns {string}
 */
const getContestName = function getContestName(contest = {}, options = {}) {
  const {
    format
  } = options;
  const {
    office,
    name: customName
  } = contest;
  const formatter = formatters[office];
  const formattedName = formatter && formatter(contest, {
    format
  });

  // TODO: should a custom name really override for all formats?
  return customName || formattedName;
};
export default getContestName;