import get from 'lodash/get';
import defaultFormats from "../constants/partyNames.js";

/**
 * Get a party's name in a particular format from the party's ID.
 *
 * @param {PartyId} party
 *   The party whose name you want to get.
 * @param {Object} [options]
 *   Additional configuration options:
 *   - `format`: The format of the name (either `letter`, `abbr` or `name`, with
 *     `abbr` being the default)
 *   - `fullPartyName`: A custom name to use for the party
 *   - `formats`: Custom formats to extend the default party name formats that
 *     are built in
 * @returns {string}
 */
const getPartyName = function getPartyName(party, options = {}) {
  const {
    format = 'abbr',
    fullPartyName,
    formats = {}
  } = options;
  const partyFormats = {
    ...get(formats, party, {}),
    ...get(defaultFormats, party, {})
  };
  // TODO: should `fullPartyName` really override in all circumstances? This
  // parallels the case of custom contests names
  return fullPartyName || partyFormats[format];
};
export default getPartyName;