'use strict';

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

var _chalk = require('chalk');

var _chalk2 = _interopRequireDefault(_chalk);

var _printTools = require('../utils/print-tools');

var _hosting = require('../utils/hosting');

var _hosting2 = _interopRequireDefault(_hosting);

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

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

class HostingAdd {
  constructor(context) {
    this.context = context;
    this.session = context.session;
    this.Socket = context.Socket;
    this.hostingName = null;
    this.socket = null;
  }

  run([hostingName, cmd]) {
    var _this = this;

    return _asyncToGenerator(function* () {
      _this.socketName = cmd.socket;
      _this.cname = cmd.cname;
      _this.fullPath = null;

      _hosting2.default.get(hostingName).then(function (hosting) {
        return hosting.configure({ cname: _this.cname });
      }).then(function (resp) {
        (0, _printTools.echo)(4)(_chalk2.default.green('Configuration successfully updated!'));
        (0, _printTools.echo)();
      }).catch(function (err) {
        try {
          (0, _printTools.error)(4)(err.response.data.detail);
        } catch (printErr) {
          (0, _printTools.error)(4)(printErr.message);
        }
        (0, _printTools.echo)();
      });
    })();
  }
}

exports.default = HostingAdd;
module.exports = exports['default'];
//# sourceMappingURL=hosting-config.js.map