import Logs from '../libs/logs.js';

const SETTING = {
  innerDefaultAmount: 10000,
  // minProfitAmount: 0,
  minShowAmount: 0,
  innerRebateRatio: 0,
  innerOuMinValue: 0,
  obRebateRatio: 0,
  obRebateType: 0,
  obMaxDiff: 0,
  imRebateRatio: 0,
  imRebateType: 0,
  imMaxDiff: 0,
  hgRebateRatio: 0,
  hgRebateType: 0,
  hgRebateLower: 0,
  hgMaxDiff: 0,
  pcRebateRatio: 0,
  pcRebateType: 0,
  innerRouSubsidyValue: 0,
  innerReMaxAdjust: 100,
  innerOuMaxAdjust: 100,
  innerWmSubsidyRatio: 0,
  innerOtSubsidyRatio: 0,
  halfTimeActiveTime: 0,
  expireTimeEvents: 45000,
  expireTimeSpecial: 60000,
  syncSettingEnabled: false,
  runWorkerEnabled: false,
}

const getSetting = (key) => {
  if (key) {
    return SETTING[key];
  }
  return SETTING;
}

const updateSetting = (fields) => {
  Object.keys(fields).forEach(key => {
    if (SETTING.hasOwnProperty(key) && SETTING[key] !== fields[key]) {
      SETTING[key] = fields[key];
      Logs.out('updateSetting', key, fields[key]);
    }
  });
}

export { getSetting, updateSetting };
export default { getSetting, updateSetting };
