'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var lodashMini_get = require('../lodash-mini/get.js');
var lodashMini_setWithString = require('../lodash-mini/set-with-string.js');
require('@babel/runtime/helpers/typeof');
require('../validate/is-index.js');

var mConfig;
/**
 * 初始化config
 * @param {ConfigType} config
 * @example
 * ```ts
 * initConfig({
 *   login: { loginType: 'WXPC' },
 *   game: 'pvp',
 * });
 *
 * getConfig('login.loginType'); // 'WXPC'
 * ```
 */
function initConfig(config) {
  mConfig = config;
}
/**
 * 获取config
 * @param {string} name
 * @return {*}  {*}
 *
 * @example
 * getConfig('login.loginType')
 * getConfig('game')
 */
function getConfig(name) {
  if (!mConfig) {
    throw new Error('config need init');
  }
  if (!name) {
    console.warn('[getConfig] 请传入name进行取值，使用setConfig，避免直接赋值');
    return mConfig;
  }
  var value = lodashMini_get.get(mConfig, name);
  if (value) return value;
  return value;
}
/**
 * 设置config
 *
 * @param {string} name
 * @param {*} value
 *
 * @example
 * setConfig('login.loginType','WXPC')
 */
function setConfig(name, value) {
  if (!mConfig) {
    throw new Error('[setConfig] config need init');
  }
  mConfig = lodashMini_setWithString.setWithString(mConfig, name, value);
}

exports.getConfig = getConfig;
exports.initConfig = initConfig;
exports.setConfig = setConfig;
