"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;
var _fileutils = require("../systemManager/fileutils");
var _logger = require("../systemManager/logger");
var _constants = require("../constants");function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}function _createClass(Constructor, protoProps, staticProps) {if (protoProps) _defineProperties(Constructor.prototype, protoProps);if (staticProps) _defineProperties(Constructor, staticProps);Object.defineProperty(Constructor, "prototype", { writable: false });return Constructor;}var

Config = /*#__PURE__*/function () {
  function Config() {_classCallCheck(this, Config);
    this.config = {};
  }_createClass(Config, [{ key: "initializeConfig", value:

    function initializeConfig(c) {
      this.config = c;
      return c;
    } }, { key: "getConfig", value:

    function getConfig() {
      return this.config;
    }

    // RNV CONFIG
  }, { key: "getConfigValueSeparate", value: function getConfigValueSeparate(key) {var global = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      var paths = this.config.paths;

      if (!global && !(0, _fileutils.fsExistsSync)(paths.project.config)) return 'N/A'; // string because there might be a setting where we will use null
      var cfg = global ?
      require(paths.GLOBAL_RNV_CONFIG) :
      require(paths.project.config);

      var value = cfg[_constants.configSchema[key].key];
      if (value === undefined) return 'N/A';

      return value;
    } }, { key: "getMergedConfigValue", value:

    function getMergedConfigValue(key) {var _this$config$buildCon;
      var value = (_this$config$buildCon = this.config.buildConfig) === null || _this$config$buildCon === void 0 ? void 0 : _this$config$buildCon[_constants.configSchema[key].key];
      if (value === undefined && _constants.configSchema[key]["default"]) {value = _constants.configSchema[key]["default"];}
      return value;
    } }, { key: "listConfigValue", value:

    function listConfigValue(key) {
      var localVal = this.getConfigValueSeparate(key).toString();
      var globalVal = this.getConfigValueSeparate(key, true).toString();

      if (globalVal === 'N/A' && _constants.configSchema[key]["default"]) {globalVal = _constants.configSchema[key]["default"];}
      if (localVal === 'N/A') localVal = globalVal;

      var table = [
      {
        Key: key,
        'Global Value': globalVal }];



      if (localVal !== 'N/A') {
        table[0]['Project Value'] = localVal;
      }

      return table;
    } }, { key: "isConfigValueValid", value:

    function isConfigValueValid(key, value) {
      var keySchema = _constants.configSchema[key];
      if (!keySchema) {
        (0, _logger.logWarning)("Unknown config param ".concat(key));
        return false;
      }

      if (keySchema.values && !keySchema.values.includes(value)) {
        (0, _logger.logWarning)("Unsupported value provided for ".concat(
        key, ". Correct values are ").concat(keySchema.values.join(
        ', ')));


        return false;
      }

      return true;
    } }, { key: "setConfigValue", value:

    function setConfigValue(key, value) {
      var _this$config =


      this.config,global = _this$config.program.global,paths = _this$config.paths;

      if (this.isConfigValueValid(key, value)) {
        var isValid = value;
        var configPath = global ?
        paths.GLOBAL_RNV_CONFIG :
        paths.project.config;
        var config = require(configPath);

        if (['true', 'false'].includes(isValid)) isValid = isValid === 'true'; // convert string to bool if it matches a bool value

        config[_constants.configSchema[key].key] = isValid;
        (0, _fileutils.writeFileSync)(configPath, config);
        return true;
      }
      return false;
    } }, { key: "isAnalyticsEnabled", get:

    function get() {
      return this.getMergedConfigValue('analytics');
    } }]);return Config;}();


var Conf = new Config();var _default =

Conf;exports["default"] = _default;
//# sourceMappingURL=config.js.map