'use strict';

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

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

var _scope;

function _load_scope() {
  return _scope = _interopRequireDefault(require('../../scope/scope'));
}

var _globalConfig;

function _load_globalConfig() {
  return _globalConfig = require('../../api/consumer/lib/global-config');
}

var _constants;

function _load_constants() {
  return _constants = require('../../constants');
}

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

var hubDomain = (0, (_globalConfig || _load_globalConfig()).getSync)((_constants || _load_constants()).CFG_HUB_DOMAIN_KEY) || (_constants || _load_constants()).DEFAULT_HUB_DOMAIN;

var hubResolver = function hubResolver(scopeName) {
  var hubPrefix = `ssh://bit@${hubDomain}:`;
  return Promise.resolve(hubPrefix + scopeName);
};

var remoteResolver = function remoteResolver(scopeName, thisScope) {
  var resolverPath = (_ramda || _load_ramda()).default.path(['scopeJson', 'resolverPath'], thisScope);
  var resolverFunction = void 0;
  if (!resolverPath) {
    resolverFunction = hubResolver;
  } else {
    // use the default resolver
    // $FlowFixMe
    resolverFunction = require(resolverPath);
  } // use the resolver described in the scopeJson

  return resolverFunction(scopeName, thisScope ? thisScope.name : undefined); // should return promise<string>
};

exports.default = remoteResolver;