import { ENV_VARS, init_paths_state, resolveStateDir } from "../../config/paths-state.js";
import { join } from "node:path";
//#region src/channels/pairing/paths.ts
init_paths_state();
function resolveDefaultCredentialsDir(env = process.env) {
	const explicit = env[ENV_VARS.CREDENTIALS_DIR]?.trim();
	if (explicit) return explicit;
	return join(resolveStateDir(env), "credentials");
}
function safeAccountKey(accountId) {
	return accountId.trim().toLowerCase().replace(/[\\/:*?"<>|]/g, "_").replace(/\.\./g, "_");
}
/** Same layout as `extensions/feishu` `resolveFeishuFrameworkAllowFromPath` for `feishu`. */
function resolveStandardAllowFromPath(channel, accountId, env = process.env) {
	const base = `xopc-${channel}`.replace(/[\\/:*?"<>|]/g, "_");
	const safe = safeAccountKey(accountId);
	return join(resolveDefaultCredentialsDir(env), `${base}-${safe}-allowFrom.json`);
}
function resolveStandardPairingPath(channel, accountId, env = process.env) {
	const base = `xopc-${channel}`.replace(/[\\/:*?"<>|]/g, "_");
	const safe = safeAccountKey(accountId);
	return join(resolveDefaultCredentialsDir(env), `${base}-${safe}-pairing.json`);
}
/** Weixin stores under `~/.xopc/weixin/credentials/` (matches `extensions/weixin` accounts helper). */
function resolveWeixinAllowFromPath(accountId, env = process.env) {
	const base = "xopc-weixin".replace(/[\\/:*?"<>|]/g, "_");
	const safe = safeAccountKey(accountId);
	return join(env[ENV_VARS.CREDENTIALS_DIR]?.trim() ? env[ENV_VARS.CREDENTIALS_DIR] : join(resolveStateDir(env), "weixin", "credentials"), `${base}-${safe}-allowFrom.json`);
}
function resolveWeixinPairingPath(accountId, env = process.env) {
	return resolveWeixinAllowFromPath(accountId, env).replace(/-allowFrom\.json$/i, "-pairing.json");
}
//#endregion
export { resolveDefaultCredentialsDir, resolveStandardAllowFromPath, resolveStandardPairingPath, resolveWeixinAllowFromPath, resolveWeixinPairingPath };

//# sourceMappingURL=paths.js.map