"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_map_set = require('../../primordials/map-set.js');
const require_external_tools_sbt_from_download = require('./from-download.js');
const require_external_tools_sbt_from_path = require('./from-path.js');
const require_external_tools_sbt_from_vfs = require('./from-vfs.js');

//#region src/external-tools/sbt/resolve.ts
/**
* @file `resolveSbt()` — SBT resolution entry point. Tries each source in
*   order:
*
*   1. VFS — smol binary's embedded `sbt-launch.jar` (if packed)
*   2. PATH — `sbt` script on the system PATH
*   3. download — upstream GitHub release tgz (only when `downloadIfMissing` is
*      passed) VFS-sourced SBT is a `.jar` that must be invoked as `java -jar
*      <path>` using the JRE resolved separately via `resolveJre()`. PATH- and
*      download-sourced SBT is the `sbt` script, which finds its own JRE.
*      Memoized per option-shape.
*/
const resolutionCache = new require_primordials_map_set.MapCtor();
function cacheKey(opts) {
	if (!opts?.downloadIfMissing) return "local-only";
	const { cacheDir, integrity, version } = opts.downloadIfMissing;
	return `dl:${version}:${typeof integrity === "string" ? integrity : integrity ? `${integrity.type}:${integrity.value}` : ""}:${cacheDir ?? ""}`;
}
async function doResolveSbt(opts) {
	const fromVfs = await require_external_tools_sbt_from_vfs.sbtFromVfs();
	/* c8 ignore start - smol Node binary only. */
	if (fromVfs) return fromVfs;
	/* c8 ignore stop */
	const fromPath = await require_external_tools_sbt_from_path.sbtFromPath();
	if (fromPath) return fromPath;
	if (opts?.downloadIfMissing) return require_external_tools_sbt_from_download.sbtFromDownload(opts.downloadIfMissing);
}
/* c8 ignore start - test-only escape hatch. */
function resetSbtResolution() {
	resolutionCache.clear();
}
/* c8 ignore stop */
function resolveSbt(opts) {
	const key = cacheKey(opts);
	let cached = resolutionCache.get(key);
	if (!cached) {
		cached = doResolveSbt(opts);
		resolutionCache.set(key, cached);
	}
	return cached;
}

//#endregion
exports.cacheKey = cacheKey;
exports.doResolveSbt = doResolveSbt;
exports.resetSbtResolution = resetSbtResolution;
exports.resolveSbt = resolveSbt;