'use strict';

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

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _bitId;

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

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var RemovedObjects = exports.RemovedObjects = function () {
  function RemovedObjects(_ref) {
    var removedComponentIds = _ref.removedComponentIds,
        missingComponents = _ref.missingComponents,
        removedDependencies = _ref.removedDependencies,
        dependentBits = _ref.dependentBits;

    _classCallCheck(this, RemovedObjects);

    this.removedComponentIds = removedComponentIds || new (_bitId || _load_bitId()).BitIds();
    this.missingComponents = missingComponents || new (_bitId || _load_bitId()).BitIds();
    this.removedDependencies = removedDependencies || new (_bitId || _load_bitId()).BitIds();
    this.dependentBits = dependentBits || {};
  }

  _createClass(RemovedObjects, [{
    key: 'serialize',
    value: function serialize() {
      return {
        removedComponentIds: this.removedComponentIds.serialize(),
        missingComponents: this.missingComponents.serialize(),
        removedDependencies: this.removedDependencies.serialize(),
        dependentBits: this.dependentBits
      };
    }
  }], [{
    key: 'fromObjects',
    value: function fromObjects(payload) {
      // this function being called from an ssh, so the ids must have a remote scope
      var missingComponents = new (Function.prototype.bind.apply((_bitId || _load_bitId()).BitIds, [null].concat(_toConsumableArray(payload.missingComponents.map(function (id) {
        return (_bitId || _load_bitId()).BitId.parse(id, true);
      })))))();
      var removedComponentIds = new (Function.prototype.bind.apply((_bitId || _load_bitId()).BitIds, [null].concat(_toConsumableArray(payload.removedComponentIds.map(function (id) {
        return (_bitId || _load_bitId()).BitId.parse(id, true);
      })))))();
      var removedDependencies = new (Function.prototype.bind.apply((_bitId || _load_bitId()).BitIds, [null].concat(_toConsumableArray(payload.removedDependencies.map(function (id) {
        return (_bitId || _load_bitId()).BitId.parse(id, true);
      })))))();
      return new RemovedObjects({
        missingComponents,
        removedComponentIds,
        removedDependencies,
        dependentBits: payload.dependentBits
      });
    }
  }]);

  return RemovedObjects;
}();

var RemovedLocalObjects = exports.RemovedLocalObjects = function (_RemovedObjects) {
  _inherits(RemovedLocalObjects, _RemovedObjects);

  function RemovedLocalObjects(removedComponentIds, missingComponents, modifiedComponents, removedDependencies, dependentBits) {
    _classCallCheck(this, RemovedLocalObjects);

    var _this = _possibleConstructorReturn(this, (RemovedLocalObjects.__proto__ || Object.getPrototypeOf(RemovedLocalObjects)).call(this, { removedComponentIds, missingComponents, removedDependencies, dependentBits }));

    _this.modifiedComponents = modifiedComponents;
    return _this;
  }

  return RemovedLocalObjects;
}(RemovedObjects);