import { init_session_key, parseSessionKey } from "../../routing/session-key.js";
import { INTERNAL_OUTBOUND_DROP_CHANNEL } from "../../channels/internal-outbound.js";
//#region src/agent/service/parse-outbound-session-key.ts
init_session_key();
/**
* Map a session key to outbound channel routing (heartbeat/cron/virtual keys included).
*/
function parseOutboundSessionKey(sessionKey, config) {
	const parts = sessionKey.split(":").filter(Boolean);
	const first = parts[0] || "cli";
	if (first === "heartbeat") {
		const hb = config?.gateway?.heartbeat;
		const target = hb?.target?.trim();
		const targetChatId = hb?.targetChatId?.trim();
		if (target && targetChatId) return {
			channel: target,
			chatId: targetChatId
		};
		return {
			channel: INTERNAL_OUTBOUND_DROP_CHANNEL,
			chatId: parts.slice(1).join(":") || "heartbeat"
		};
	}
	const parsed = parseSessionKey(sessionKey);
	if (parsed) return {
		channel: parsed.source,
		chatId: parsed.peerId
	};
	if (first === "cron") return {
		channel: INTERNAL_OUTBOUND_DROP_CHANNEL,
		chatId: parts.slice(1).join(":") || "cron"
	};
	return {
		channel: first,
		chatId: parts.slice(1).join(":") || "direct"
	};
}
//#endregion
export { parseOutboundSessionKey };

//# sourceMappingURL=parse-outbound-session-key.js.map