"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 _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 _scope() {
  const data = require("../../../api/scope");

  _scope = function () {
    return data;
  };

  return data;
}

function _generalError() {
  const data = _interopRequireDefault(require("../../../error/general-error"));

  _generalError = function () {
    return data;
  };

  return data;
}

class ResolverSet extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'set <resolverPath>');
    (0, _defineProperty2().default)(this, "description", 'set remote resolver to scope (use from scope directory)');
    (0, _defineProperty2().default)(this, "alias", 's');
    (0, _defineProperty2().default)(this, "private", true);
    (0, _defineProperty2().default)(this, "opts", []);
  }

  action([resolverPath]) {
    if (!resolverPath) {
      // @TODO mandatory arguments do not work for sub commands - please fix !
      throw new (_generalError().default)('resolverPath is mandatory');
    }

    return (0, _scope().setResolver)(process.cwd(), resolverPath).then(() => resolverPath);
  }

  report(resolverPath) {
    return `resolver path has changed successfully to - ${_chalk().default.yellow(resolverPath)}`;
  }

}

class ResolverReset extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'reset');
    (0, _defineProperty2().default)(this, "description", 'reset remote resolver to default resolver');
    (0, _defineProperty2().default)(this, "alias", 'r');
    (0, _defineProperty2().default)(this, "opts", []);
  }

  action() {
    return (0, _scope().resetResolver)(process.cwd());
  }

  report() {
    return 'resovler path has successfully reset to default';
  }

}

class Resolver extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'resolver');
    (0, _defineProperty2().default)(this, "description", 'get or set remote resolver to scope');
    (0, _defineProperty2().default)(this, "alias", '');
    (0, _defineProperty2().default)(this, "opts", []);
    (0, _defineProperty2().default)(this, "commands", [new ResolverSet(), new ResolverReset()]);
    (0, _defineProperty2().default)(this, "private", true);
  }

  action() {
    return (0, _scope().getResolver)(process.cwd());
  }

  report(resovlerPath) {
    if (!resovlerPath) {
      return 'there is no resolver path, bit uses the default resolver';
    }

    return _chalk().default.yellow(resovlerPath);
  }

}

exports.default = Resolver;