import { l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CIXf7egm.js";
import "./string-coerce-runtime-C8jKEm3h.js";
import { c as defineStableChannelIngressIdentity } from "./channel-ingress-runtime-BD8SdNdV.js";
import { m as resolveScopeRequireMention, u as buildChannelGroupsScopeTree } from "./channel-policy-5rjTzLKN.js";
//#region extensions/googlechat/src/group-policy.ts
function buildGoogleChatGroupPolicyScope(params) {
	const matchKey = params.groupId && Object.hasOwn(params.tree.scopes, params.groupId) ? params.groupId : void 0;
	return {
		tree: params.tree,
		path: matchKey ? [matchKey] : [],
		matchKey
	};
}
function resolveGoogleChatGroupRequireMention(params) {
	return resolveScopeRequireMention(buildGoogleChatGroupPolicyScope({
		tree: buildChannelGroupsScopeTree(params.cfg, "googlechat", params.accountId),
		groupId: params.groupId
	}));
}
//#endregion
//#region extensions/googlechat/src/ingress-identity.ts
function normalizeGoogleChatUserId(raw) {
	const trimmed = normalizeOptionalString(raw) ?? "";
	if (!trimmed) return "";
	return normalizeLowercaseStringOrEmpty(trimmed.replace(/^users\//i, ""));
}
const GOOGLECHAT_EMAIL_KIND = "plugin:googlechat-email";
function normalizeEntryValue(raw) {
	return normalizeLowercaseStringOrEmpty(raw ?? "");
}
function normalizeGoogleChatStableEntry(entry) {
	const withoutProvider = normalizeEntryValue(entry).replace(/^(googlechat|google-chat|gchat):/i, "");
	if (!withoutProvider) return null;
	return withoutProvider.startsWith("users/") ? normalizeGoogleChatUserId(withoutProvider) : withoutProvider;
}
function normalizeGoogleChatEmailEntry(entry) {
	if (normalizeEntryValue(entry).replace(/^(googlechat|google-chat|gchat):/i, "").startsWith("users/")) return null;
	const stable = normalizeGoogleChatStableEntry(entry);
	return stable?.includes("@") ? stable : null;
}
const googleChatIngressIdentity = defineStableChannelIngressIdentity({
	key: "sender-id",
	authentication: "verified",
	normalizeEntry: normalizeGoogleChatStableEntry,
	normalizeSubject: normalizeGoogleChatUserId,
	aliases: [{
		key: "email",
		kind: GOOGLECHAT_EMAIL_KIND,
		normalizeEntry: normalizeGoogleChatEmailEntry,
		normalizeSubject: normalizeEntryValue,
		authentication: "mutable"
	}],
	isWildcardEntry: (entry) => normalizeEntryValue(entry) === "*",
	resolveEntryId: ({ entryIndex, fieldKey }) => fieldKey === "stableId" ? `entry-${entryIndex + 1}:user` : `entry-${entryIndex + 1}:${fieldKey}`
});
//#endregion
export { resolveGoogleChatGroupRequireMention as i, normalizeGoogleChatUserId as n, buildGoogleChatGroupPolicyScope as r, googleChatIngressIdentity as t };
