'use strict';

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

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _command;

function _load_command() {
  return _command = _interopRequireDefault(require('../../command'));
}

var _chalk;

function _load_chalk() {
  return _chalk = _interopRequireDefault(require('chalk'));
}

var _utils;

function _load_utils() {
  return _utils = require('../../../utils');
}

var _scope;

function _load_scope() {
  return _scope = require('../../../api/scope');
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var ScopeConfig = function (_Command) {
  _inherits(ScopeConfig, _Command);

  function ScopeConfig() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, ScopeConfig);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ScopeConfig.__proto__ || Object.getPrototypeOf(ScopeConfig)).call.apply(_ref, [this].concat(args))), _this), _this.name = 'scope-config', _this.description = 'scope config management', _this.alias = '', _this.commands = [new ScopeConfigSet(), new ScopeConfigDel(), new ScopeConfigGet(), new ScopeConfigList()], _this.opts = [], _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(ScopeConfig, [{
    key: 'action',
    value: function action() {
      return (_scope || _load_scope()).scopeConfig.list();
    }
  }, {
    key: 'report',
    value: function report(conf) {
      return (0, (_utils || _load_utils()).objectToStringifiedTupleArray)(conf).map(function (tuple) {
        return tuple.join('     ');
      }).join('\n');
    }
  }]);

  return ScopeConfig;
}((_command || _load_command()).default);

exports.default = ScopeConfig;

var ScopeConfigSet = function (_Command2) {
  _inherits(ScopeConfigSet, _Command2);

  function ScopeConfigSet() {
    var _ref2;

    var _temp2, _this2, _ret2;

    _classCallCheck(this, ScopeConfigSet);

    for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
      args[_key2] = arguments[_key2];
    }

    return _ret2 = (_temp2 = (_this2 = _possibleConstructorReturn(this, (_ref2 = ScopeConfigSet.__proto__ || Object.getPrototypeOf(ScopeConfigSet)).call.apply(_ref2, [this].concat(args))), _this2), _this2.name = 'set <key> <val>', _this2.description = 'set a scope configuration', _this2.alias = '', _this2.private = true, _this2.opts = [], _temp2), _possibleConstructorReturn(_this2, _ret2);
  }

  _createClass(ScopeConfigSet, [{
    key: 'action',
    value: function action(_ref3) {
      var _ref4 = _slicedToArray(_ref3, 2),
          key = _ref4[0],
          value = _ref4[1];

      return (_scope || _load_scope()).scopeConfig.set(key, value);
    }
  }, {
    key: 'report',
    value: function report(_ref5) {
      var key = _ref5.key,
          value = _ref5.value;

      return `${(_chalk || _load_chalk()).default.yellow(key)} has been set to - ${(_chalk || _load_chalk()).default.yellow(value)}`;
    }
  }]);

  return ScopeConfigSet;
}((_command || _load_command()).default);

var ScopeConfigGet = function (_Command3) {
  _inherits(ScopeConfigGet, _Command3);

  function ScopeConfigGet() {
    var _ref6;

    var _temp3, _this3, _ret3;

    _classCallCheck(this, ScopeConfigGet);

    for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
      args[_key3] = arguments[_key3];
    }

    return _ret3 = (_temp3 = (_this3 = _possibleConstructorReturn(this, (_ref6 = ScopeConfigGet.__proto__ || Object.getPrototypeOf(ScopeConfigGet)).call.apply(_ref6, [this].concat(args))), _this3), _this3.name = 'get <key>', _this3.description = 'get a scope configuration', _this3.alias = '', _this3.private = true, _this3.opts = [], _temp3), _possibleConstructorReturn(_this3, _ret3);
  }

  _createClass(ScopeConfigGet, [{
    key: 'action',
    value: function action(_ref7) {
      var _ref8 = _slicedToArray(_ref7, 1),
          key = _ref8[0];

      return (_scope || _load_scope()).scopeConfig.get(key);
    }
  }, {
    key: 'report',
    value: function report(value) {
      return value;
    }
  }]);

  return ScopeConfigGet;
}((_command || _load_command()).default);

var ScopeConfigList = function (_Command4) {
  _inherits(ScopeConfigList, _Command4);

  function ScopeConfigList() {
    var _ref9;

    var _temp4, _this4, _ret4;

    _classCallCheck(this, ScopeConfigList);

    for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
      args[_key4] = arguments[_key4];
    }

    return _ret4 = (_temp4 = (_this4 = _possibleConstructorReturn(this, (_ref9 = ScopeConfigList.__proto__ || Object.getPrototypeOf(ScopeConfigList)).call.apply(_ref9, [this].concat(args))), _this4), _this4.name = 'list', _this4.description = 'list all scope configuration(s)', _this4.alias = '', _this4.opts = [], _temp4), _possibleConstructorReturn(_this4, _ret4);
  }

  _createClass(ScopeConfigList, [{
    key: 'action',
    value: function action() {
      return (_scope || _load_scope()).scopeConfig.list();
    }
  }, {
    key: 'report',
    value: function report(conf) {
      return (0, (_utils || _load_utils()).objectToStringifiedTupleArray)(conf).map(function (tuple) {
        return tuple.join('     ');
      }).join('\n');
    }
  }]);

  return ScopeConfigList;
}((_command || _load_command()).default);

var ScopeConfigDel = function (_Command5) {
  _inherits(ScopeConfigDel, _Command5);

  function ScopeConfigDel() {
    var _ref10;

    var _temp5, _this5, _ret5;

    _classCallCheck(this, ScopeConfigDel);

    for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
      args[_key5] = arguments[_key5];
    }

    return _ret5 = (_temp5 = (_this5 = _possibleConstructorReturn(this, (_ref10 = ScopeConfigDel.__proto__ || Object.getPrototypeOf(ScopeConfigDel)).call.apply(_ref10, [this].concat(args))), _this5), _this5.name = 'del <key>', _this5.description = 'delete given key from global configuration', _this5.alias = '', _this5.opts = [], _temp5), _possibleConstructorReturn(_this5, _ret5);
  }

  _createClass(ScopeConfigDel, [{
    key: 'action',
    value: function action(_ref11) {
      var _ref12 = _slicedToArray(_ref11, 1),
          key = _ref12[0];

      return (_scope || _load_scope()).scopeConfig.del(key);
    }
  }, {
    key: 'report',
    value: function report(conf) {
      return 'deleted successfully';
    }
  }]);

  return ScopeConfigDel;
}((_command || _load_command()).default);