import { i as GATEWAY_CLIENT_NAMES, r as GATEWAY_CLIENT_MODES } from "./client-info-CcqJJIan.js";
import { c as callGateway } from "./call-BT2IYnTG.js";
import { r as withProgress } from "./progress-CN3xUiCO.js";
import { n as parseTimeoutMsWithFallback } from "./parse-timeout-DZMZaF9B.js";
//#region src/cli/nodes-cli/rpc.runtime.ts
const NODE_PAIR_APPROVAL_GATEWAY_METHODS = new Set(["node.pair.list", "node.pair.approve"]);
const DEFAULT_NODES_RPC_TIMEOUT_MS = 1e4;
function resolveNodesTransportTimeoutMs(opts, overrideMs) {
	return overrideMs ?? parseTimeoutMsWithFallback(opts.timeout, DEFAULT_NODES_RPC_TIMEOUT_MS);
}
async function callGatewayCliRuntime(method, opts, params, callOpts) {
	return await withProgress({
		label: `Nodes ${method}`,
		indeterminate: true,
		enabled: opts.json !== true
	}, async () => await callGateway({
		url: opts.url,
		token: opts.token,
		method,
		params,
		scopes: callOpts?.scopes,
		useStoredDeviceAuth: callOpts?.useStoredDeviceAuth,
		requiredStoredDeviceAuthScopes: callOpts?.requiredStoredDeviceAuthScopes,
		requireLocalBackendSharedAuth: callOpts?.useLocalBackendSharedAuth,
		timeoutMs: resolveNodesTransportTimeoutMs(opts, callOpts?.transportTimeoutMs),
		clientName: callOpts?.useLocalBackendSharedAuth ? GATEWAY_CLIENT_NAMES.GATEWAY_CLIENT : GATEWAY_CLIENT_NAMES.CLI,
		mode: callOpts?.useLocalBackendSharedAuth ? GATEWAY_CLIENT_MODES.BACKEND : GATEWAY_CLIENT_MODES.CLI
	}));
}
async function callNodePairApprovalGatewayCliRuntime(method, opts, params, callOpts) {
	if (!NODE_PAIR_APPROVAL_GATEWAY_METHODS.has(method)) throw new Error(`unsupported node pair approval gateway method: ${method}`);
	return await withProgress({
		label: `Nodes ${method}`,
		indeterminate: true,
		enabled: opts.json !== true
	}, async () => await callGateway({
		url: opts.url,
		token: opts.token,
		method,
		params,
		timeoutMs: resolveNodesTransportTimeoutMs(opts, callOpts.transportTimeoutMs),
		clientName: GATEWAY_CLIENT_NAMES.GATEWAY_CLIENT,
		mode: GATEWAY_CLIENT_MODES.BACKEND,
		scopes: callOpts.scopes
	}));
}
//#endregion
export { callGatewayCliRuntime, callNodePairApprovalGatewayCliRuntime };
