"use strict";

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

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

function _object() {
  const data = _interopRequireDefault(require("../objects/object"));

  _object = function () {
    return data;
  };

  return data;
}

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

  _utils = function () {
    return data;
  };

  return data;
}

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

  _bitId = function () {
    return data;
  };

  return data;
}

class Symlink extends _object().default {
  constructor(props) {
    super();
    this.scope = props.scope;
    this.name = props.name;
    this.realScope = props.realScope;
  }

  id() {
    return this.name;
  }

  getRealComponentId() {
    return new (_bitId().BitId)({
      scope: this.realScope,
      name: this.name
    });
  }

  static parse(contents) {
    const rawContent = JSON.parse(contents);
    if (rawContent.box) rawContent.name = `${rawContent.box}/${rawContent.name}`;
    return Symlink.from(rawContent);
  }

  toObject() {
    return {
      scope: this.scope,
      name: this.name,
      realScope: this.realScope
    };
  }

  toBitId() {
    return new (_bitId().BitId)({
      name: this.name
    });
  }

  toBuffer(pretty) {
    const args = (0, _utils().getStringifyArgs)(pretty);
    return Buffer.from(JSON.stringify(this.toObject(), ...args));
  }

  static from(props) {
    return new Symlink(props);
  }

}

exports.default = Symlink;