'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

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 _objects;

function _load_objects() {
  return _objects = require('../objects');
}

var _constants;

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

var _utils;

function _load_utils() {
  return _utils = require('../../utils');
}

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"); } }

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; }

var Symlink = function (_BitObject) {
  _inherits(Symlink, _BitObject);

  function Symlink(props) {
    _classCallCheck(this, Symlink);

    var _this = _possibleConstructorReturn(this, (Symlink.__proto__ || Object.getPrototypeOf(Symlink)).call(this));

    _this.scope = props.scope;
    _this.name = props.name;
    _this.box = props.box || (_constants || _load_constants()).DEFAULT_BOX_NAME;
    _this.realScope = props.realScope;
    return _this;
  }

  _createClass(Symlink, [{
    key: 'id',
    value: function id() {
      return [this.box, this.name].join('/');
    }
  }, {
    key: 'getRealComponentId',
    value: function getRealComponentId() {
      return [this.realScope, this.box, this.name].join('/');
    }
  }, {
    key: 'toObject',
    value: function toObject() {
      return {
        scope: this.scope,
        box: this.box,
        name: this.name,
        realScope: this.realScope
      };
    }
  }, {
    key: 'toBuffer',
    value: function toBuffer(pretty) {
      var args = (0, (_utils || _load_utils()).getStringifyArgs)(pretty);
      return Buffer.from(JSON.stringify.apply(JSON, [this.toObject()].concat(_toConsumableArray(args))));
    }
  }], [{
    key: 'parse',
    value: function parse(contents) {
      var rawContent = JSON.parse(contents);
      return Symlink.from(rawContent);
    }
  }, {
    key: 'from',
    value: function from(props) {
      return new Symlink(props);
    }
  }]);

  return Symlink;
}((_objects || _load_objects()).BitObject);

exports.default = Symlink;