'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 _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 ScopeMeta = function (_BitObject) {
  _inherits(ScopeMeta, _BitObject);

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

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

    _this.license = props.license;
    _this.name = props.name;
    return _this;
  }

  _createClass(ScopeMeta, [{
    key: 'toObject',
    value: function toObject() {
      return {
        license: this.license,
        name: this.name
      };
    }
  }, {
    key: 'toString',
    value: function toString(pretty) {
      var args = (0, (_utils || _load_utils()).getStringifyArgs)(pretty);
      return JSON.stringify.apply(JSON, [this.toObject()].concat(_toConsumableArray(args)));
    }
  }, {
    key: 'id',
    value: function id() {
      return this.name;
    }
  }, {
    key: 'toBuffer',
    value: function toBuffer(pretty) {
      return (0, (_utils || _load_utils()).bufferFrom)(this.toString(pretty));
    }
  }], [{
    key: 'fromScopeName',
    value: function fromScopeName(name) {
      return ScopeMeta.fromObject({ name }).hash();
    }
  }, {
    key: 'parse',
    value: function parse(propsStr) {
      return this.fromObject(JSON.parse(propsStr));
    }
  }, {
    key: 'fromObject',
    value: function fromObject(props) {
      return new ScopeMeta(props);
    }
  }, {
    key: 'from',
    value: function from(props) {
      return ScopeMeta.fromObject(props);
    }
  }]);

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

exports.default = ScopeMeta;