'use strict';

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

var _chalk = require('chalk');

var _chalk2 = _interopRequireDefault(_chalk);

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

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 SocketAddDep {
  constructor(context) {
    this.session = context.session;
    this.Socket = context.Socket;
    this.registry = new context.Registry();
  }

  run([socketNameArg, dependencyNameArg]) {
    var _this = this;

    return _asyncToGenerator(function* () {
      const socketName = socketNameArg;
      const [dependencyName] = dependencyNameArg.split('==');

      _this.socket = yield _this.Socket.get(socketName);

      return _this.registry.searchSocketByName(dependencyName).then(function (socketFromRegistry) {
        return _this.socket.addDependency(socketFromRegistry).then(function () {
          const msg = ['Dependency was found in the registry and added to config file: ', `${_chalk2.default.cyan(socketFromRegistry.name)} ${_chalk2.default.dim(`(${socketFromRegistry.version})`)}`].join('');
          (0, _printTools.echo)();
          (0, _printTools.echo)(4)(_chalk2.default.green('✓'), msg);
          (0, _printTools.echo)();
        });
      });
    })();
  }
}
exports.default = SocketAddDep;
module.exports = exports['default'];
//# sourceMappingURL=socket-add-dep.js.map