"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function _defineProperty2() {
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

  _defineProperty2 = function () {
    return data;
  };

  return data;
}

function _padRight() {
  const data = _interopRequireDefault(require("pad-right"));

  _padRight = function () {
    return data;
  };

  return data;
}

function _chalk() {
  const data = _interopRequireDefault(require("chalk"));

  _chalk = function () {
    return data;
  };

  return data;
}

function _command() {
  const data = _interopRequireDefault(require("../../command"));

  _command = function () {
    return data;
  };

  return data;
}

function _utils() {
  const data = require("../../../utils");

  _utils = function () {
    return data;
  };

  return data;
}

function _constants() {
  const data = require("../../../constants");

  _constants = function () {
    return data;
  };

  return data;
}

// import { config } from '../../../api/consumer';
const config = require('../../../api/consumer/lib/global-config');

class Config extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'config');
    (0, _defineProperty2().default)(this, "description", `global config management.\n  https://${_constants().BASE_DOCS_DOMAIN}/docs/conf-config.html`);
    (0, _defineProperty2().default)(this, "alias", '');
    (0, _defineProperty2().default)(this, "commands", [new ConfigSet(), new ConfigDel(), new ConfigGet(), new ConfigList()]);
    (0, _defineProperty2().default)(this, "opts", []);
    (0, _defineProperty2().default)(this, "migration", false);
  }

  action() {
    return config.list();
  }

  report(conf) {
    return (0, _utils().objectToTupleArray)(conf).map(tuple => {
      tuple[0] = (0, _padRight().default)(tuple[0], 30, ' ');
      return tuple.join('');
    }).join('\n');
  }

}

exports.default = Config;

class ConfigSet extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'set <key> <val>');
    (0, _defineProperty2().default)(this, "description", 'set a global configuration');
    (0, _defineProperty2().default)(this, "alias", '');
    (0, _defineProperty2().default)(this, "opts", []);
  }

  action([key, value]) {
    return config.set(key, value);
  }

  report(conf) {
    return _chalk().default.green('added configuration successfully');
  }

}

class ConfigGet extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'get <key>');
    (0, _defineProperty2().default)(this, "description", 'get a global configuration');
    (0, _defineProperty2().default)(this, "alias", '');
    (0, _defineProperty2().default)(this, "opts", []);
  }

  action([key]) {
    return config.get(key);
  }

  report(value) {
    return value;
  }

}

class ConfigList extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'list');
    (0, _defineProperty2().default)(this, "description", 'list all configuration(s)');
    (0, _defineProperty2().default)(this, "alias", '');
    (0, _defineProperty2().default)(this, "opts", []);
  }

  action() {
    return config.list();
  }

  report(conf) {
    return (0, _utils().objectToTupleArray)(conf).map(tuple => {
      return tuple.join('     ');
    }).join('\n');
  }

}

class ConfigDel extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'del <key>');
    (0, _defineProperty2().default)(this, "description", 'delete given key from global configuration');
    (0, _defineProperty2().default)(this, "alias", '');
    (0, _defineProperty2().default)(this, "opts", []);
  }

  action([key]) {
    return config.del(key);
  }

  report(conf) {
    return _chalk().default.green('deleted successfully');
  }

}