"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

function _defineProperty2() {
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

  _defineProperty2 = function () {
    return data;
  };

  return data;
}

function _command() {
  const data = _interopRequireDefault(require("../../command"));

  _command = function () {
    return data;
  };

  return data;
}

function _utils() {
  const data = require("../../../utils");

  _utils = function () {
    return data;
  };

  return data;
}

function _scope() {
  const data = require("../../../api/scope");

  _scope = function () {
    return data;
  };

  return data;
}

function _consumer() {
  const data = require("../../../api/consumer");

  _consumer = function () {
    return data;
  };

  return data;
}

function _logger() {
  const data = _interopRequireDefault(require("../../../logger/logger"));

  _logger = function () {
    return data;
  };

  return data;
}

function _checkVersionCompatibility() {
  const data = require("../../../scope/network/check-version-compatibility");

  _checkVersionCompatibility = function () {
    return data;
  };

  return data;
}

class _Graph extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", '_graph <path> <args>');
    (0, _defineProperty2().default)(this, "private", true);
    (0, _defineProperty2().default)(this, "description", 'returns scope graph or sub-graph when component id is given');
    (0, _defineProperty2().default)(this, "alias", '');
    (0, _defineProperty2().default)(this, "opts", []);
  }

  action([path, args]) {
    const {
      payload,
      headers
    } = (0, _utils().unpackCommand)(args);
    (0, _checkVersionCompatibility().checkVersionCompatibilityOnTheServer)(headers.version);

    _logger().default.info('Checking if a migration is needed');

    const scopePath = (0, _utils().fromBase64)(path);
    return (0, _consumer().migrate)(scopePath, false).then(() => {
      return (0, _scope().graph)(scopePath, payload);
    });
  }

  report(str) {
    return (0, _utils().packCommand)((0, _utils().buildCommandMessage)(str));
  }

}

exports.default = _Graph;