import { createLogger } from "../../../src/utils/logger/index.js";
import { init_logger } from "../../../src/utils/logger.js";
import { buildSessionKey } from "../../../src/routing/session-key.js";
import { applyIdentityLinks, resolveRoute } from "../../../src/routing/resolve-route.js";
import "../../../src/routing/index.js";
//#region extensions/telegram/src/routing-integration.ts
init_logger();
const log = createLogger("TelegramRouting");
/**
* Generate session key with routing integration
*/
function generateSessionKeyWithRouting(ctx, config) {
	const channel = ctx.channel ?? "telegram";
	const route = resolveRoute({
		config,
		channel,
		accountId: ctx.accountId,
		peerKind: ctx.isGroup ? "group" : "dm",
		peerId: ctx.isGroup ? ctx.chatId : ctx.senderId,
		guildId: ctx.guildId ?? null,
		teamId: null,
		memberRoleIds: ctx.memberRoleIds ?? [],
		threadId: ctx.threadId
	});
	const identityLinks = config.session?.identityLinks ?? {};
	const finalPeerId = applyIdentityLinks(ctx.isGroup ? ctx.chatId : ctx.senderId, channel, identityLinks);
	const finalSessionKey = buildSessionKey({
		agentId: route.agentId,
		source: channel,
		accountId: route.accountId,
		peerKind: ctx.isGroup ? "group" : "dm",
		peerId: finalPeerId,
		threadId: ctx.threadId
	});
	log.debug({
		accountId: ctx.accountId,
		chatId: ctx.chatId,
		senderId: ctx.senderId,
		sessionKey: finalSessionKey,
		agentId: route.agentId
	}, "Generated session key with routing");
	return finalSessionKey;
}
/**
* Extract member role IDs from Telegram chat member
* (Currently returns empty array as Telegram doesn't have direct role mapping)
*/
function extractMemberRoleIds(ctx) {
	const chatMember = ctx.chatMember;
	if (!chatMember?.new_chat_member) return [];
	const roles = [];
	const memberStatus = chatMember.new_chat_member.status;
	if (memberStatus === "creator") roles.push("telegram:creator");
	else if (memberStatus === "administrator") roles.push("telegram:admin");
	return roles;
}
//#endregion
export { extractMemberRoleIds, generateSessionKeyWithRouting };

//# sourceMappingURL=routing-integration.js.map