import { resolveStandardAllowFromPath } from "../../../../src/channels/pairing/paths.js";
import { readAllowFromIdsSync } from "../../../../src/channels/pairing/allow-from-file.js";
import { evaluateAccess, resolveDmPolicy, resolveGroupPolicy } from "../../../../src/channels/security.js";
//#region extensions/telegram/src/adapters/security-adapter.ts
function createTelegramSecurityAdapter() {
	return {
		resolveDmPolicy: ({ account }) => resolveDmPolicy(account.dmPolicy, "pairing"),
		resolveGroupPolicy: ({ account }) => resolveGroupPolicy(account.groupPolicy, "open"),
		resolveAllowFrom: ({ account }) => account.allowFrom,
		checkAccess: (ctx, account, _cfg) => {
			const isGroup = ctx.isGroup;
			const storeAllow = !isGroup ? readAllowFromIdsSync(resolveStandardAllowFromPath("telegram", account.accountId)) : [];
			const allowFrom = isGroup ? account.groupAllowFrom ?? account.allowFrom ?? [] : [...account.allowFrom ?? [], ...storeAllow];
			const result = evaluateAccess({
				context: {
					channel: "telegram",
					accountId: account.accountId,
					chatId: ctx.chatId,
					senderId: ctx.senderId,
					senderName: ctx.senderName,
					isGroup,
					isDm: !isGroup
				},
				dmPolicy: account.dmPolicy,
				groupPolicy: account.groupPolicy,
				allowFrom,
				groupAllowFrom: account.groupAllowFrom
			});
			return {
				allowed: result.allowed,
				reason: result.reason
			};
		}
	};
}
//#endregion
export { createTelegramSecurityAdapter };

//# sourceMappingURL=security-adapter.js.map