'use strict';

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

var _inquirer = require('inquirer');

var _inquirer2 = _interopRequireDefault(_inquirer);

var _chalk = require('chalk');

var _chalk2 = _interopRequireDefault(_chalk);

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

var _hosting2 = _interopRequireDefault(_hosting);

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 HostingDelete {
  constructor(context) {
    this.context = context;
    this.session = context.session;
    this.Socket = context.Socket;
    this.Hosting = context.Hosting;
  }

  static getQuestions(hostingName) {
    const questions = [{
      type: 'confirm',
      name: 'delete',
      message: (0, _printTools.p)(2)(`Are you sure you want to remove: ${_chalk2.default.red(hostingName)}`),
      default: false
    }];

    return questions;
  }

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

    return _asyncToGenerator(function* () {
      _this.cmd = cmd;
      if (cmd.socket) {
        // TODO: impement Socket level hosting
      } else {
        return _inquirer2.default.prompt(HostingDelete.getQuestions(hostingName)).then(function (resp) {
          if (!resp.delete) {
            (0, _printTools.echo)();
            process.exit(0);
          }
          return _hosting2.default.get(hostingName).then(function (hosting) {
            if (!hosting.existLocally) {
              (0, _printTools.warning)((0, _printTools.p)(4)(`Couldn't find any hosting named ${_chalk2.default.cyan(hostingName)}!`));
              (0, _printTools.echo)();
              process.exit(1);
            }
            hosting.delete();
            (0, _printTools.echo)(4)(`Hosting ${_chalk2.default.cyan(hosting.name)} has been ${_chalk2.default.green('successfully')} deleted!`);
            (0, _printTools.echo)();
          });
        });
      }
    })();
  }
}
exports.default = HostingDelete;
module.exports = exports['default'];
//# sourceMappingURL=hosting-delete.js.map