import semver from 'semver';
export var AgentType;
(function (AgentType) {
    AgentType[AgentType["MULTITENANT"] = 0] = "MULTITENANT";
    AgentType[AgentType["DEDICATED"] = 1] = "DEDICATED";
    AgentType[AgentType["ONPREMISE"] = 2] = "ONPREMISE";
})(AgentType || (AgentType = {}));
// This function returns a descriptive name for each known agent type
export const getAgentTypeName = (agentType) => {
    switch (agentType) {
        case AgentType.DEDICATED:
        case AgentType.MULTITENANT:
            return 'Cloud';
        case AgentType.ONPREMISE:
            return 'On-premise';
    }
};
export 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 || (AgentStatus = {}));
export 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 || (AgentsHealthStatus = {}));
export const compareSemVer = (version1, version2) => {
    if (!semver.valid(version1)) {
        throw new Error(`Invalid semver ${version1}.`);
    }
    if (!semver.valid(version2)) {
        throw new Error(`Invalid semver ${version2}.`);
    }
    return semver.compare(version1, version2);
};
/**
 * 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.
 */
export const compareAgentExternalVersions = ({ currentVersion, minVersion }) => {
    const isCurrentVersionValid = semver.valid(currentVersion);
    const isMinVersionValid = semver.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.compare(currentVersion, minVersion);
};
//# sourceMappingURL=agent.js.map