import { resolveStateDir } from "../config/paths-state.js";
import { init_paths } from "../config/paths.js";
import { mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
//#region src/tunnel/frpc-config.ts
init_paths();
function resolveFrpcConfigPath(tunnelId) {
	const tmpDir = join(resolveStateDir(), "tmp");
	mkdirSync(tmpDir, { recursive: true });
	return join(tmpDir, `frpc-${tunnelId}.toml`);
}
function writeFrpcConfig(registration, localPort, localHost = "127.0.0.1", mode = "http") {
	const configPath = resolveFrpcConfigPath(registration.tunnelId);
	const { frpc } = registration;
	writeFileSync(configPath, `# Auto-generated by xopc — do not edit
serverAddr = "${frpc.serverAddr}"
serverPort = ${frpc.serverPort}
metadatas.token = "${frpc.authToken}"

loginFailExit = false
transport.heartbeatInterval = 10
transport.heartbeatTimeout = 30

[[proxies]]
name = "${frpc.proxyName}"
type = "${mode}"
localIP = "${localHost}"
localPort = ${localPort}
subdomain = "${registration.subdomain}"
`, "utf8");
	return configPath;
}
//#endregion
export { resolveFrpcConfigPath, writeFrpcConfig };

//# sourceMappingURL=frpc-config.js.map