"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.compareAgentExternalVersions = exports.compareSemVer = exports.AgentsHealthStatus = exports.AgentStatus = exports.getAgentTypeName = exports.AgentType = void 0;
const semver_1 = __importDefault(require("semver"));
var AgentType;
(function (AgentType) {
    AgentType[AgentType["MULTITENANT"] = 0] = "MULTITENANT";
    AgentType[AgentType["DEDICATED"] = 1] = "DEDICATED";
    AgentType[AgentType["ONPREMISE"] = 2] = "ONPREMISE";
})(AgentType || (exports.AgentType = AgentType = {}));
// This function returns a descriptive name for each known agent type
const getAgentTypeName = (agentType) => {
    switch (agentType) {
        case AgentType.DEDICATED:
        case AgentType.MULTITENANT:
            return 'Cloud';
        case AgentType.ONPREMISE:
            return 'On-premise';
    }
};
exports.getAgentTypeName = getAgentTypeName;
var AgentStatus;
(function (AgentStatus) {
    AgentStatus["ACTIVE"] = "Active";
    AgentStatus["DISCONNECTED"] = "Disconnected";
    AgentStatus["BROWSER_UNREACHABLE"] = "Browser Unreachable";
    // TODO: remove PENDING_REGISTRATION after the DB migration
    AgentStatus["PENDING_REGISTRATION"] = "Pending Registration";
    AgentStatus["STALE"] = "Stale";
})(AgentStatus || (exports.AgentStatus = AgentStatus = {}));
var AgentsHealthStatus;
(function (AgentsHealthStatus) {
    AgentsHealthStatus["HEALTHY"] = "HEALTHY";
    /* No connected agents exist */
    AgentsHealthStatus["NO_AGENTS"] = "NO_AGENTS";
    /* There are connected agents, but none for the current profile */
    AgentsHealthStatus["NO_AGENTS_FOR_PROFILE"] = "NO_AGENTS_FOR_PROFILE";
    /* There are connected agents for the current profile, but none are reachable from the browser */
    AgentsHealthStatus["NO_REACHABLE_AGENTS"] = "NO_REACHABLE_AGENTS";
    /* The health of the agents is unknown */
    AgentsHealthStatus["UNKNOWN"] = "UNKNOWN";
})(AgentsHealthStatus || (exports.AgentsHealthStatus = AgentsHealthStatus = {}));
const compareSemVer = (version1, version2) => {
    if (!semver_1.default.valid(version1)) {
        throw new Error(`Invalid semver ${version1}.`);
    }
    if (!semver_1.default.valid(version2)) {
        throw new Error(`Invalid semver ${version2}.`);
    }
    return semver_1.default.compare(version1, version2);
};
exports.compareSemVer = compareSemVer;
/**
 * Return a negative number if version1 is lower than version2;
 * positive if the version1 is greater than version2;
 * 0 if they are equivalent.
 *
 * If the versions are both invalid, return 0.
 * Otherwise, the valid version is treated as greater than an invalid version.
 */
const compareAgentExternalVersions = ({ currentVersion, minVersion }) => {
    const isCurrentVersionValid = semver_1.default.valid(currentVersion);
    const isMinVersionValid = semver_1.default.valid(minVersion);
    // If both versions are invalid, return 0.
    if (!isCurrentVersionValid && !isMinVersionValid) {
        return 0;
    }
    if (!isCurrentVersionValid) {
        // If the current version is invalid, treat it as lower than the min version.
        return -1;
    }
    else if (!isMinVersionValid) {
        // If the min version is invalid, treat it as lower than the current version.
        return 1;
    }
    return semver_1.default.compare(currentVersion, minVersion);
};
exports.compareAgentExternalVersions = compareAgentExternalVersions;
//# sourceMappingURL=agent.js.map