import { MavenDatasource } from "../../modules/datasource/maven/index.js";
import { NugetDatasource } from "../../modules/datasource/nuget/index.js";
//#region lib/util/vulnerability/utils.ts
/**
* Ecosystems/datasources that use Maven-style inclusive ranges for fixed versions: `[version,)`
*/
const mavenStyleFixedEcosystems = new Set([MavenDatasource.id, NugetDatasource.id]);
/**
* Ecosystems/datasources that use Maven-style exclusive ranges for last-affected versions: `(version,)`
*/
const mavenStyleLastAffectedEcosystems = new Set([MavenDatasource.id]);
/**
* Formats a fixed version as an allowed-version constraint appropriate for the ecosystem.
*
* @param fixedVersion - The first version that contains the fix
* @param ecosystem - Ecosystem or datasource name (e.g., 'maven', 'npm', 'nuget'). Checked in a case-insensitive manner.
*/
function getFixedVersionConstraint(fixedVersion, ecosystem) {
	if (mavenStyleFixedEcosystems.has(ecosystem.toLowerCase())) return `[${fixedVersion},)`;
	return `>= ${fixedVersion}`;
}
/**
* Formats a last-affected version as an allowed-version constraint appropriate for the ecosystem.
*
* @param lastAffected - The last version known to be affected
* @param ecosystem - Ecosystem or datasource name. Checked in a case-insensitive manner.
*/
function getLastAffectedVersionConstraint(lastAffected, ecosystem) {
	if (mavenStyleLastAffectedEcosystems.has(ecosystem.toLowerCase())) return `(${lastAffected},)`;
	return `> ${lastAffected}`;
}
const severityOrder = {
	LOW: 1,
	MEDIUM: 2,
	MODERATE: 2,
	HIGH: 3,
	CRITICAL: 4,
	UNKNOWN: 5
};
function getHighestVulnerabilitySeverity(parent, child) {
	const parentVulSeverity = parent.vulnerabilitySeverity?.toUpperCase();
	const childVulSeverity = child?.vulnerabilitySeverity?.toUpperCase();
	if (childVulSeverity === void 0) return parentVulSeverity;
	if (parentVulSeverity === void 0) return childVulSeverity;
	return severityOrder[parentVulSeverity] >= severityOrder[childVulSeverity] ? parentVulSeverity : childVulSeverity;
}
//#endregion
export { getFixedVersionConstraint, getHighestVulnerabilitySeverity, getLastAffectedVersionConstraint };

//# sourceMappingURL=utils.js.map