import { y as resolveStateDir } from "./paths-CU1mLMSe.js";
import process$1 from "node:process";
import path from "node:path";
import { randomUUID } from "node:crypto";
//#region src/proxy-capture/paths.ts
function resolveDebugProxyRootDir(env = process.env) {
	return path.join(resolveStateDir(env), "debug-proxy");
}
function resolveDebugProxyDbPath(env = process.env) {
	return path.join(resolveDebugProxyRootDir(env), "capture.sqlite");
}
function resolveDebugProxyBlobDir(env = process.env) {
	return path.join(resolveDebugProxyRootDir(env), "blobs");
}
function resolveDebugProxyCertDir(env = process.env) {
	return path.join(resolveDebugProxyRootDir(env), "certs");
}
//#endregion
//#region src/proxy-capture/env.ts
const NODMIX_DEBUG_PROXY_ENABLED = "NODMIX_DEBUG_PROXY_ENABLED";
const NODMIX_DEBUG_PROXY_URL = "NODMIX_DEBUG_PROXY_URL";
const NODMIX_DEBUG_PROXY_DB_PATH = "NODMIX_DEBUG_PROXY_DB_PATH";
const NODMIX_DEBUG_PROXY_BLOB_DIR = "NODMIX_DEBUG_PROXY_BLOB_DIR";
const NODMIX_DEBUG_PROXY_CERT_DIR = "NODMIX_DEBUG_PROXY_CERT_DIR";
const NODMIX_DEBUG_PROXY_SESSION_ID = "NODMIX_DEBUG_PROXY_SESSION_ID";
const NODMIX_DEBUG_PROXY_REQUIRE = "NODMIX_DEBUG_PROXY_REQUIRE";
let cachedImplicitSessionId;
function isTruthy(value) {
	return value === "1" || value === "true" || value === "yes" || value === "on";
}
function resolveDebugProxySettings(env = process$1.env) {
	const enabled = isTruthy(env[NODMIX_DEBUG_PROXY_ENABLED]);
	const sessionId = (env["NODMIX_DEBUG_PROXY_SESSION_ID"]?.trim() || void 0) ?? (cachedImplicitSessionId ??= randomUUID());
	return {
		enabled,
		required: isTruthy(env[NODMIX_DEBUG_PROXY_REQUIRE]),
		proxyUrl: env["NODMIX_DEBUG_PROXY_URL"]?.trim() || void 0,
		dbPath: env["NODMIX_DEBUG_PROXY_DB_PATH"]?.trim() || resolveDebugProxyDbPath(env),
		blobDir: env["NODMIX_DEBUG_PROXY_BLOB_DIR"]?.trim() || resolveDebugProxyBlobDir(env),
		certDir: env["NODMIX_DEBUG_PROXY_CERT_DIR"]?.trim() || resolveDebugProxyCertDir(env),
		sessionId,
		sourceProcess: "nodmix"
	};
}
function applyDebugProxyEnv(env, params) {
	return {
		...env,
		[NODMIX_DEBUG_PROXY_ENABLED]: "1",
		[NODMIX_DEBUG_PROXY_REQUIRE]: "1",
		[NODMIX_DEBUG_PROXY_URL]: params.proxyUrl,
		[NODMIX_DEBUG_PROXY_DB_PATH]: params.dbPath ?? resolveDebugProxyDbPath(env),
		[NODMIX_DEBUG_PROXY_BLOB_DIR]: params.blobDir ?? resolveDebugProxyBlobDir(env),
		[NODMIX_DEBUG_PROXY_CERT_DIR]: params.certDir ?? resolveDebugProxyCertDir(env),
		[NODMIX_DEBUG_PROXY_SESSION_ID]: params.sessionId,
		HTTP_PROXY: params.proxyUrl,
		HTTPS_PROXY: params.proxyUrl,
		ALL_PROXY: params.proxyUrl
	};
}
function createDebugProxyWebSocketAgent(settings) {
	if (!settings.enabled || !settings.proxyUrl) return;
	settings.proxyUrl, settings.proxyUrl;
}
function resolveEffectiveDebugProxyUrl(configuredProxyUrl) {
	const explicit = configuredProxyUrl?.trim();
	if (explicit) return explicit;
	const settings = resolveDebugProxySettings();
	return settings.enabled ? settings.proxyUrl : void 0;
}
//#endregion
export { resolveEffectiveDebugProxyUrl as i, createDebugProxyWebSocketAgent as n, resolveDebugProxySettings as r, applyDebugProxyEnv as t };
