'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.undeprecate = exports.deprecate = undefined;

var _regenerator;

function _load_regenerator() {
  return _regenerator = _interopRequireDefault(require('babel-runtime/regenerator'));
}

var _bluebird;

function _load_bluebird() {
  return _bluebird = require('bluebird');
}

var deprecate = exports.deprecate = function () {
  var _ref = (0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee(_ref2) {
    var ids = _ref2.ids,
        remote = _ref2.remote;
    var consumer, bitIds;
    return (_regenerator || _load_regenerator()).default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            if (remote) (_loader || _load_loader()).default.start((_loaderMessages || _load_loaderMessages()).BEFORE_REMOTE_DEPRECATE);
            _context.next = 3;
            return (0, (_consumer || _load_consumer()).loadConsumer)();

          case 3:
            consumer = _context.sent;
            bitIds = getBitIds(ids, remote, consumer);
            return _context.abrupt('return', consumer.deprecate(bitIds, remote));

          case 6:
          case 'end':
            return _context.stop();
        }
      }
    }, _callee, this);
  }));

  return function deprecate(_x) {
    return _ref.apply(this, arguments);
  };
}();

var undeprecate = exports.undeprecate = function () {
  var _ref3 = (0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee2(_ref4) {
    var ids = _ref4.ids,
        remote = _ref4.remote;
    var consumer, bitIds;
    return (_regenerator || _load_regenerator()).default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            if (remote) (_loader || _load_loader()).default.start((_loaderMessages || _load_loaderMessages()).BEFORE_REMOTE_UNDEPRECATE);
            _context2.next = 3;
            return (0, (_consumer || _load_consumer()).loadConsumer)();

          case 3:
            consumer = _context2.sent;
            bitIds = getBitIds(ids, remote, consumer);
            return _context2.abrupt('return', consumer.undeprecate(bitIds, remote));

          case 6:
          case 'end':
            return _context2.stop();
        }
      }
    }, _callee2, this);
  }));

  return function undeprecate(_x2) {
    return _ref3.apply(this, arguments);
  };
}();

var _consumer;

function _load_consumer() {
  return _consumer = require('../../../consumer');
}

var _loader;

function _load_loader() {
  return _loader = _interopRequireDefault(require('../../../cli/loader'));
}

var _loaderMessages;

function _load_loaderMessages() {
  return _loaderMessages = require('../../../cli/loader/loader-messages');
}

var _bitId;

function _load_bitId() {
  return _bitId = require('../../../bit-id');
}

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

function getBitIds(ids, remote, consumer) {
  return ids.map(function (id) {
    return remote ? (_bitId || _load_bitId()).BitId.parse(id, true) : consumer.getParsedId(id);
  });
}