import { getStateName } from "../index.js";

/**
 * Utility to format names of Sec. State contests
 *
 * @param {Object} metadata
 * @param {Object} opts
 * @param {string} opts.format
 * @returns {string}
 */
const stateAttyGenContestName = function stateAttyGenContestName(metadata, opts = {}) {
  const {
    stateFips
  } = metadata;
  const {
    format = 'long'
  } = opts;

  // e.g., "NM"
  if (format === 'tiny') {
    return getStateName(stateFips, {
      format: 'abbr'
    });
  }

  // e.g., "NM A.G."
  if (format === 'short') {
    const stateName = getStateName(stateFips, {
      format: 'abbr'
    });
    return `${stateName} A.G.`;
  }

  // e.g., "N.M. Attorney General"
  if (format === 'medium') {
    const stateName = getStateName(stateFips, {
      format: 'ap_abbr'
    });
    return `${stateName} Attorney General`;
  }

  // e.g., "Attorney General"
  if (format === 'no-state') {
    return 'Attorney General';
  }

  // e.g., "N.M. Attorney General"
  const stateName = getStateName(stateFips, {
    format: 'ap_abbr'
  });
  return `${stateName} Attorney General`;
};
export default stateAttyGenContestName;