'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, headers) {
    var path = _ref2.path,
        ids = _ref2.ids;
    var bitIds, args, scope, deprecationResult, hookArgs;
    return (_regenerator || _load_regenerator()).default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            bitIds = (_bitId || _load_bitId()).BitIds.deserialize(ids);
            args = { path, bitIds };

            HooksManagerInstance.triggerHook((_constants || _load_constants()).PRE_DEPRECATE_REMOTE, args, headers);
            _context.next = 5;
            return (0, (_scope || _load_scope()).loadScope)(path);

          case 5:
            scope = _context.sent;
            _context.next = 8;
            return (0, (_componentsDeprecation || _load_componentsDeprecation()).deprecateMany)(scope, bitIds);

          case 8:
            deprecationResult = _context.sent;
            hookArgs = {
              deprecatedComponentsIds: deprecationResult.bitIds,
              missingComponentsIds: deprecationResult.missingComponents,
              scopePath: path,
              componentsIds: bitIds.serialize(),
              scopeName: scope.scopeJson.name
            };
            _context.next = 12;
            return HooksManagerInstance.triggerHook((_constants || _load_constants()).POST_DEPRECATE_REMOTE, hookArgs, headers);

          case 12:
            return _context.abrupt('return', deprecationResult);

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

  return function deprecate(_x, _x2) {
    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, headers) {
    var path = _ref4.path,
        ids = _ref4.ids;
    var bitIds, args, scope, deprecationResult, hookArgs;
    return (_regenerator || _load_regenerator()).default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            bitIds = (_bitId || _load_bitId()).BitIds.deserialize(ids);
            args = { path, bitIds };

            HooksManagerInstance.triggerHook((_constants || _load_constants()).PRE_UNDEPRECATE_REMOTE, args, headers);
            _context2.next = 5;
            return (0, (_scope || _load_scope()).loadScope)(path);

          case 5:
            scope = _context2.sent;
            _context2.next = 8;
            return (0, (_componentsDeprecation || _load_componentsDeprecation()).undeprecateMany)(scope, bitIds);

          case 8:
            deprecationResult = _context2.sent;
            hookArgs = {
              deprecatedComponentsIds: deprecationResult.bitIds,
              missingComponentsIds: deprecationResult.missingComponents,
              scopePath: path,
              componentsIds: bitIds.serialize(),
              scopeName: scope.scopeJson.name
            };
            _context2.next = 12;
            return HooksManagerInstance.triggerHook((_constants || _load_constants()).POST_UNDEPRECATE_REMOTE, hookArgs, headers);

          case 12:
            return _context2.abrupt('return', deprecationResult);

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

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

var _scope;

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

var _bitId;

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

var _constants;

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

var _hooks;

function _load_hooks() {
  return _hooks = _interopRequireDefault(require('../../../hooks'));
}

var _componentsDeprecation;

function _load_componentsDeprecation() {
  return _componentsDeprecation = require('../../../scope/component-ops/components-deprecation');
}

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

var HooksManagerInstance = (_hooks || _load_hooks()).default.getInstance();