"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_trufflehog_from_download = require('./from-download.js');
const require_external_tools_trufflehog_from_path = require('./from-path.js');
const require_external_tools_trufflehog_from_vfs = require('./from-vfs.js');

//#region src/external-tools/trufflehog/resolve.ts
/**
* @file `resolveTrufflehog()` — TruffleHog resolution entry point. Tries each
*   source in order:
*
*   1. VFS — smol binary's embedded TruffleHog (if packed)
*   2. PATH — `trufflehog` on the system PATH
*   3. download — upstream GitHub release tar.gz (only when `downloadIfMissing` is
*      passed) Returns `undefined` if all of the enabled sources miss. Memoized
*      per option-shape; same caching semantics as `resolveJre()`.
*/
const resolutionCache = new require_primordials_map_set.MapCtor();
function cacheKey(opts) {
	if (!opts?.downloadIfMissing) return "local-only";
	const { cacheDir, integrity, platformArch, version } = opts.downloadIfMissing;
	return `dl:${version}:${platformArch}:${typeof integrity === "string" ? integrity : integrity ? `${integrity.type}:${integrity.value}` : ""}:${cacheDir ?? ""}`;
}
async function doResolveTrufflehog(opts) {
	const fromVfs = await require_external_tools_trufflehog_from_vfs.trufflehogFromVfs();
	/* c8 ignore start - smol Node binary only. */
	if (fromVfs) return fromVfs;
	/* c8 ignore stop */
	const fromPath = await require_external_tools_trufflehog_from_path.trufflehogFromPath();
	if (fromPath) return fromPath;
	if (opts?.downloadIfMissing) return require_external_tools_trufflehog_from_download.trufflehogFromDownload(opts.downloadIfMissing);
}
/* c8 ignore start - test-only escape hatch. */
function resetTrufflehogResolution() {
	resolutionCache.clear();
}
/* c8 ignore stop */
function resolveTrufflehog(opts) {
	const key = cacheKey(opts);
	let cached = resolutionCache.get(key);
	if (!cached) {
		cached = doResolveTrufflehog(opts);
		resolutionCache.set(key, cached);
	}
	return cached;
}

//#endregion
exports.cacheKey = cacheKey;
exports.doResolveTrufflehog = doResolveTrufflehog;
exports.resetTrufflehogResolution = resetTrufflehogResolution;
exports.resolveTrufflehog = resolveTrufflehog;