"use strict";

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

function _bitId() {
  const data = require("../bit-id");

  _bitId = function () {
    return data;
  };

  return data;
}

class RemovedObjects {
  constructor({
    removedComponentIds,
    missingComponents,
    removedDependencies,
    dependentBits
  }) {
    this.removedComponentIds = removedComponentIds || new (_bitId().BitIds)();
    this.missingComponents = missingComponents || new (_bitId().BitIds)();
    this.removedDependencies = removedDependencies || new (_bitId().BitIds)();
    this.dependentBits = dependentBits || {};
  }

  serialize() {
    return {
      removedComponentIds: this.removedComponentIds.serialize(),
      missingComponents: this.missingComponents.serialize(),
      removedDependencies: this.removedDependencies.serialize(),
      dependentBits: this.dependentBits
    };
  }

  static fromObjects(payload) {
    // this function being called from an ssh, so the ids must have a remote scope
    const missingComponents = new (_bitId().BitIds)(...payload.missingComponents.map(id => _bitId().BitId.parse(id, true)));
    const removedComponentIds = new (_bitId().BitIds)(...payload.removedComponentIds.map(id => _bitId().BitId.parse(id, true)));
    const removedDependencies = new (_bitId().BitIds)(...payload.removedDependencies.map(id => _bitId().BitId.parse(id, true)));
    const dependentBits = Object.keys(payload.dependentBits).reduce((acc, current) => {
      acc[current] = new (_bitId().BitIds)(...payload.dependentBits[current].map(id => new (_bitId().BitId)(id)));
      return acc;
    }, {});
    return new RemovedObjects({
      missingComponents,
      removedComponentIds,
      removedDependencies,
      dependentBits
    });
  }

}

exports.RemovedObjects = RemovedObjects;

class RemovedLocalObjects extends RemovedObjects {
  constructor(removedComponentIds, missingComponents, modifiedComponents, removedDependencies, dependentBits) {
    super({
      removedComponentIds,
      missingComponents,
      removedDependencies,
      dependentBits
    });
    this.modifiedComponents = modifiedComponents;
  }

}

exports.RemovedLocalObjects = RemovedLocalObjects;