import lodash from "lodash";
function callFunctions(obj) {
  if (typeof obj === "function") {
    return obj();
  }
  return obj;
}
function resolveValues(obj) {
  return Object.entries(obj).reduce(
    (acc, curr) => ({
      ...acc,
      [curr[1] && curr[0]]: callFunctions(curr[1])
    }),
    {}
  );
}
function getCommonFields(obj) {
  if (!obj || Object.keys(obj).length === 0) {
    return {};
  }
  const {
    bsi,
    metaSiteId,
    visitorId,
    visitor_id,
    // (visitorId) multiple variations, same value
    _appId,
    _instanceId,
    _msid,
    // (metaSiteId) multiple variations, same value
    _siteOwnerId
  } = resolveValues(obj);
  return lodash.pickBy(
    {
      bsi,
      visitorId: visitor_id || visitorId,
      appId: _appId,
      instanceId: _instanceId,
      metaSiteId: _msid || metaSiteId,
      siteOwnerId: _siteOwnerId
    },
    lodash.identity
  );
}
function fromBiLoggerFactory(biLoggerFactory) {
  const obj = lodash.merge(
    {},
    biLoggerFactory?.()?.loggerClientFactory?._defaults,
    biLoggerFactory?.()?.loggerClientFactory?._nonEssentialDefaults
  );
  return getCommonFields(obj);
}
function fromBiObject(bi) {
  return getCommonFields(bi);
}
function fromBiLogger(biLogger) {
  const obj = biLogger?.biLoggerClientFactoryInstance?.loggerClientFactory?._defaults;
  return getCommonFields(obj);
}
const extractUoUParams = ({
  bi,
  biLogger,
  biLoggerFactory,
  platformAPIs
} = {}) => {
  return lodash.merge(
    fromBiObject(bi || platformAPIs?.bi),
    fromBiLogger(biLogger),
    fromBiLoggerFactory(biLoggerFactory || platformAPIs?.biLoggerFactory)
  );
};
export {
  extractUoUParams
};
//# sourceMappingURL=extract-uou-params.js.map
