import get from 'lodash/get';
import makeBylines from './makeBylines';
const makeUtagConfig = function makeUtagConfig(baseConf) {
  const authors = get(baseConf, 'authors', []).map(a => {
    if (typeof a === 'string') {
      return a;
    }
    if (typeof a === 'object' && 'name' in a) {
      return a.name;
    }
    return '';
  });
  const abTestingId = get(baseConf, 'ab_testing') || get(baseConf, 'abTesting') || get(baseConf, 'AbTesting') || get(baseConf, 'ABTesting') || undefined;
  const usingAbTesting = !!abTestingId;
  return {
    ...baseConf,
    page_level_1: get(baseConf, 'page_level_1') || 'interactives',
    free_paid_content: get(baseConf, 'freePaidContent') || get(baseConf, 'free_paid_content') || 'free',
    ad_unit_section: get(baseConf, 'adUnitSection') || get(baseConf, 'ad_unit_section') || 'politics',
    adssetup: get(baseConf, 'adssetup'),
    site_section: get(baseConf, 'siteSection') || get(baseConf, 'site_section') || null,
    page_type: get(baseConf, 'pageType') || get(baseConf, 'page_type') || null,
    page_sub_type: get(baseConf, 'pageSubType') || get(baseConf, 'page_sub_type') || undefined,
    content_tag: get(baseConf, 'contentTag') || get(baseConf, 'content_tag') || undefined,
    site_domain: get(baseConf, 'site_domain') || 'www.politico.com',
    internal_site_id: get(baseConf, 'internalSiteId') || get(baseConf, 'internal_site_id') || 'politico',
    enable_prebid: get(baseConf, 'enable_prebid') || true,
    content_author: authors.join('|'),
    content_byline: `By ${makeBylines(authors)}`,
    series: get(baseConf, 'series') || undefined,
    subseries: get(baseConf, 'subseries') || undefined,
    ab_test_name: abTestingId,
    ab_test_view: usingAbTesting
  };
};
export default makeUtagConfig;