"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const VersionParts = 3;
/*
  immutable structure defining semantic versioning with 3 parts: major, minor, and patch
*/
class SemanticVersion {
    major;
    minor;
    patch;
    static parse(version) {
        if (!version) {
            return undefined;
        }
        if (Array.isArray(version)) {
            return SemanticVersion.fromArray(version);
        }
        if (typeof version === "number") {
            return SemanticVersion.fromNumber(version);
        }
        return SemanticVersion.fromString(version);
    }
    static fromNumber(version) {
        if (version < 0) {
            return undefined;
        }
        const major = Math.floor(version);
        return new SemanticVersion(major, version - major, 0);
    }
    static fromString(version) {
        const tokens = version.split(".");
        if (tokens.length === 0) {
            return undefined;
        }
        const versionNums = tokens.map((num) => parseInt(num));
        if (versionNums.some(Number.isNaN)) {
            return undefined;
        }
        return new SemanticVersion(versionNums[0], versionNums[1] || 0, versionNums[2] || 0);
    }
    static fromArray(versionNums) {
        if (!versionNums || versionNums.length !== VersionParts) {
            return undefined;
        }
        return new SemanticVersion(versionNums[0], versionNums[1], versionNums[2]);
    }
    get majorVersion() {
        return this.major;
    }
    get minorVersion() {
        return this.minor;
    }
    get patchVersion() {
        return this.patch;
    }
    constructor(major, minor, patch) {
        this.major = major;
        this.minor = minor;
        this.patch = patch;
    }
    asString() {
        return `${this.major}.${this.minor}.${this.patch}`;
    }
    asArray() {
        return [this.major, this.minor, this.patch];
    }
    equals(other) {
        return this.major === other.major && this.minor === other.minor && this.patch === other.patch;
    }
    increment(major = 0, minor = 0, patch = 0) {
        return new SemanticVersion(this.major + major, this.minor + minor, this.patch + patch);
    }
    /*
      returns a numeric comparison value
      0 is equal, <0 (i.e. negative values) mean this is less than the other value, >0 mean this is greater than the other value
    */
    compareTo(other) {
        return this.major - other.major || this.minor - other.minor || this.patch - other.patch;
    }
}
exports.default = SemanticVersion;

//# sourceMappingURL=../../maps/core/versioning/SemanticVersion.js.map
