"use strict";

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

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

function _semver() {
  const data = _interopRequireDefault(require("semver"));

  _semver = function () {
    return data;
  };

  return data;
}

function _exceptions() {
  const data = require("./exceptions");

  _exceptions = function () {
    return data;
  };

  return data;
}

function _constants() {
  const data = require("../constants");

  _constants = function () {
    return data;
  };

  return data;
}

class Version {
  constructor(versionNum, latest) {
    this.versionNum = versionNum;
    this.latest = latest;
  }

  increase(releaseType = _constants().DEFAULT_BIT_RELEASE_TYPE) {
    if (!this.versionNum) throw new (_exceptions().InvalidVersionChange)();
    this.versionNum = _semver().default.inc(this.versionNum, releaseType);
    return this;
  }

  resolve(availableVersion) {
    const getLatest = () => _semver().default.maxSatisfying(availableVersion, '*');

    if (this.latest) return getLatest();
    return this.versionNum;
  }

  toString() {
    if (!this.versionNum && this.latest) return 'latest';
    if (this.versionNum && this.latest) return `*${this.versionNum}`;
    if (this.versionNum && !this.latest) return this.versionNum.toString();
    throw new (_exceptions().InvalidVersion)();
  }

}

exports.default = Version;