import { logger } from "../../../logger/index.js";
import { DateTime } from "luxon";

//#region lib/modules/versioning/debian/common.ts
const refreshInterval = { days: 1 };
var RollingReleasesData = class {
	ltsToVer = /* @__PURE__ */ new Map();
	verToLts = /* @__PURE__ */ new Map();
	timestamp = DateTime.fromMillis(0).toUTC();
	distroInfo;
	constructor(distroInfo) {
		this.distroInfo = distroInfo;
	}
	getVersionByLts(input) {
		this.build();
		const schedule = this.ltsToVer.get(input);
		if (schedule) return schedule.version;
		return input;
	}
	getLtsByVersion(input) {
		this.build();
		const di = this.verToLts.get(input);
		if (di) return di.series;
		return input;
	}
	has(version) {
		this.build();
		return this.ltsToVer.has(version);
	}
	schedule(version) {
		this.build();
		let schedule = void 0;
		if (this.verToLts.has(version)) schedule = this.verToLts.get(version);
		if (this.ltsToVer.has(version)) schedule = this.ltsToVer.get(version);
		return schedule;
	}
	build() {
		const now = DateTime.now().toUTC();
		if (now < this.timestamp.plus(refreshInterval)) return;
		logger.debug("RollingReleasesData - data written");
		this.timestamp = now;
		for (let i = 0; i < 3; i++) {
			const di = this.distroInfo.getNLatest(i);
			if (!di) return;
			let prefix = "";
			for (let j = 0; j < i; j++) prefix += "old";
			di.series = prefix + "stable";
			this.ltsToVer.set(di.series, di);
			this.verToLts.set(di.version, di);
		}
	}
};

//#endregion
export { RollingReleasesData };
//# sourceMappingURL=common.js.map