import { init_session_key, sanitizeSegment } from "../../../../src/routing/session-key.js";
//#region extensions/weixin/src/auth/weixin-account-id.ts
init_session_key();
/**
* Canonical Weixin bot account id (ilink / state paths).
* Kept separate from `accounts.ts` so token store can import it without circular deps with `inbound`.
*/
function normalizeWeixinAccountId(raw) {
	return raw.trim().toLowerCase().replace(/@/g, "-").replace(/\./g, "-").replace(/[^a-z0-9_-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
}
/**
* Peer id as in session keys / context-token map (same rules as `buildSessionKey` peer segment).
*/
function canonicalWeixinPeerId(rawPeerId) {
	const t = rawPeerId.trim();
	return sanitizeSegment(t, { allowLeadingDash: true }) || t.toLowerCase();
}
const ILINK_WECHAT_USER_SUFFIX = "-im-wechat";
/**
* ilink sendmessage / getUploadUrl / getconfig expect `…@im.wechat` for C2C users.
* Session/cron addresses use sanitized `…-im-wechat` (from `sanitizeSegment`); map back before API calls.
*/
function toRawIlinkUserIdForApi(peerId) {
	const t = peerId.trim();
	if (t.includes("@")) return t;
	if (t.toLowerCase().endsWith(ILINK_WECHAT_USER_SUFFIX)) return `${t.slice(0, t.length - 10)}@im.wechat`;
	return t;
}
//#endregion
export { canonicalWeixinPeerId, normalizeWeixinAccountId, toRawIlinkUserIdForApi };

//# sourceMappingURL=weixin-account-id.js.map