/**
 * Group Chat Security
 *
 * OpenClaw-inspired group chat security with mention-gating, group allowlists,
 * and activation control.
 *
 * In group chats, bots can be noisy if they respond to every message. This
 * module provides configurable security controls:
 *
 * 1. **Mention-gating** - Require @mention to activate in groups
 * 2. **Group allowlists** - Per-group user allowlists
 * 3. **Activation modes** - Per-group control (active, mention-only, inactive, allowlist-only)
 * 4. **Global blocklist** - Block users across all groups
 * 5. **Rate limiting** - Per-group message rate limiting
 *
 * Usage:
 * ```typescript
 * const security = getGroupSecurity();
 *
 * // Check if an inbound message should be processed
 * const result = security.shouldProcess(message);
 * if (result.allowed) {
 *   // Process message
 * } else {
 *   logger.debug('Message blocked', { reason: result.reason });
 * }
 *
 * // Configure a group
 * security.addGroup({
 *   groupId: 'telegram:-100123456',
 *   channelType: 'telegram',
 *   activationMode: 'mention-only',
 *   allowedUsers: ['user-1', 'user-2'],
 * });
 * ```
 */
import { EventEmitter } from 'events';
import type { ChannelType, InboundMessage } from './index.js';
/**
 * Group activation mode controlling how the bot responds in a group.
 *
 * - `active` - Process all messages (no gating)
 * - `mention-only` - Only process messages that mention the bot
 * - `inactive` - Ignore all messages in this group
 * - `allowlist-only` - Only process messages from allowlisted users
 */
export type GroupActivationMode = 'active' | 'mention-only' | 'inactive' | 'allowlist-only';
/**
 * Per-group configuration
 */
export interface GroupConfig {
    /** Group/channel ID */
    groupId: string;
    /** Channel type (telegram, discord, etc.) */
    channelType: ChannelType;
    /** How the bot is activated in this group */
    activationMode: GroupActivationMode;
    /** Users allowed to interact in this group (for allowlist-only mode) */
    allowedUsers?: string[];
    /** Custom mention patterns for this group (overrides global) */
    mentionPatterns?: string[];
    /** Whether mentions are required in this group (default true for groups) */
    requireMention?: boolean;
    /** Cooldown between processed messages in ms */
    cooldownMs?: number;
    /** Maximum messages per minute for this group */
    maxMessagesPerMinute?: number;
}
/**
 * Global group security configuration
 */
export interface GroupSecurityConfig {
    /** Enable group security */
    enabled: boolean;
    /** Default activation mode for unconfigured groups */
    defaultMode: GroupActivationMode;
    /** Default mention patterns to detect bot mentions */
    mentionPatterns: string[];
    /** Per-group configurations (groupId -> config) */
    groupConfigs: Map<string, GroupConfig>;
    /** Users allowed in all groups */
    globalAllowlist: string[];
    /** Users blocked from all groups */
    blocklist: string[];
    /** Require @mention in group chats by default */
    requireMentionInGroups: boolean;
}
/**
 * Result of shouldProcess check
 */
export interface ProcessResult {
    /** Whether the message should be processed */
    allowed: boolean;
    /** Human-readable reason for the decision */
    reason: string;
}
export declare const DEFAULT_GROUP_SECURITY_CONFIG: GroupSecurityConfig;
export declare class GroupSecurityManager extends EventEmitter {
    private config;
    private rateLimits;
    constructor(config?: Partial<GroupSecurityConfig>);
    /**
     * Determine whether an inbound message should be processed.
     *
     * DM (direct message) channels always pass through.
     * Group messages are checked against activation mode, mention patterns,
     * allowlists, blocklist, and rate limits.
     */
    shouldProcess(message: InboundMessage): ProcessResult;
    /**
     * Check if message content contains any of the mention patterns.
     * Case-insensitive matching.
     */
    private containsMention;
    /**
     * Check if a group has exceeded its rate limit.
     */
    private checkRateLimit;
    /**
     * Record a processed message for rate limiting purposes.
     */
    private recordMessage;
    /**
     * Add a group configuration.
     */
    addGroup(config: GroupConfig): void;
    /**
     * Remove a group configuration.
     */
    removeGroup(groupId: string): boolean;
    /**
     * Update a group configuration (partial merge).
     */
    updateGroup(groupId: string, partial: Partial<GroupConfig>): boolean;
    /**
     * Get configuration for a specific group.
     */
    getGroupConfig(groupId: string): GroupConfig | undefined;
    /**
     * List all configured groups.
     */
    listGroups(): GroupConfig[];
    /**
     * Add a user to a group's allowlist.
     */
    addToAllowlist(groupId: string, userId: string): boolean;
    /**
     * Remove a user from a group's allowlist.
     */
    removeFromAllowlist(groupId: string, userId: string): boolean;
    /**
     * Add a user to the global blocklist.
     */
    addToBlocklist(userId: string): void;
    /**
     * Remove a user from the global blocklist.
     */
    removeFromBlocklist(userId: string): boolean;
    /**
     * Get group security statistics.
     */
    getStats(): {
        enabled: boolean;
        totalGroups: number;
        defaultMode: GroupActivationMode;
        globalAllowlistSize: number;
        blocklistSize: number;
        groupsByMode: Record<string, number>;
    };
    /**
     * Dispose all internal state and remove all listeners.
     */
    dispose(): void;
}
/**
 * Get the singleton GroupSecurityManager instance.
 */
export declare function getGroupSecurity(config?: Partial<GroupSecurityConfig>): GroupSecurityManager;
/**
 * Reset the singleton GroupSecurityManager (for testing).
 */
export declare function resetGroupSecurity(): void;
