/**
 * RealtimeService - PostgreSQL WAL-based realtime change data capture
 *
 * This service uses PostgreSQL logical replication to capture database changes
 * and broadcast them via WebSockets using the existing SocketService.
 *
 * Similar to Supabase Realtime, it allows enabling realtime on specific collections
 * with granular control over which actions (insert, update, delete) trigger events.
 *
 * Realtime configuration is stored in the schema definition:
 * {
 *   "realtime": {
 *     "enabled": true,
 *     "actions": ["insert", "update", "delete"]
 *   }
 * }
 *
 * NOTE: This service ONLY works when PostgreSQL has wal_level=logical configured.
 * If WAL is not available, no realtime broadcasting will occur.
 */
export interface RealtimeConfig {
    enabled: boolean;
    actions: Array<'insert' | 'update' | 'delete'>;
}
declare class RealtimeService {
    private initialized;
    private connected;
    private replicationService;
    private socketService;
    private collectionConfigs;
    private reconnectTimeout;
    private shuttingDown;
    private walAvailable;
    private isWalLeader;
    private instanceId;
    private redisClient;
    private leaderRenewalInterval;
    constructor();
    /**
     * Set the socket service instance for broadcasting
     */
    setSocketService(socketService: any): void;
    /**
     * Check if PostgreSQL logical replication is enabled
     */
    checkLogicalReplicationEnabled(): Promise<{
        enabled: boolean;
        walLevel: string;
        error?: string;
    }>;
    /**
     * Check replication configuration
     */
    checkReplicationConfig(): Promise<{
        walLevel: string;
        maxReplicationSlots: number;
        maxWalSenders: number;
        isConfigured: boolean;
        issues: string[];
    }>;
    /**
     * Initialize the realtime service
     * Creates publication and replication slot if they don't exist
     * Only works when PostgreSQL has wal_level=logical configured
     */
    initialize(): Promise<void>;
    /**
     * Check if WAL-based realtime is available
     */
    isWalAvailable(): boolean;
    /**
     * Ensure the publication exists
     */
    private ensurePublicationExists;
    /**
     * Ensure the replication slot exists
     */
    private ensureReplicationSlotExists;
    /**
     * Load collections with realtime enabled from schema definitions
     * Supports both old format (realtime: true) and new format (realtime: { enabled: true, actions: [...] })
     */
    private loadEnabledCollections;
    /**
     * Sync the PostgreSQL publication with enabled collections
     */
    private syncPublicationWithCollections;
    /**
     * Start consuming WAL changes
     */
    startConsuming(): Promise<void>;
    /**
     * Try to become the WAL consumer leader using Redis
     * Uses SETNX with TTL - only one instance can hold the key
     */
    private tryBecomeWalLeader;
    /**
     * Start periodic renewal of leader lock
     */
    private startLeaderRenewal;
    /**
     * Stop leader renewal interval
     */
    private stopLeaderRenewal;
    /**
     * Release WAL leader lock in Redis
     */
    private releaseWalLeaderLock;
    /**
     * Get or create Redis client for leader election
     * Reuses the same Redis URL as Socket.IO
     */
    private getRedisClient;
    /**
     * Handle WAL messages and broadcast changes
     */
    private handleWalMessage;
    /**
     * Handle disconnect and attempt reconnection
     */
    private handleDisconnect;
    /**
     * Enable realtime for a collection with specific actions
     */
    enableCollection(collectionName: string, actions?: Array<'insert' | 'update' | 'delete'>): Promise<void>;
    /**
     * Disable realtime for a collection
     */
    disableCollection(collectionName: string): Promise<void>;
    /**
     * Update realtime actions for a collection
     */
    updateCollectionActions(collectionName: string, actions: Array<'insert' | 'update' | 'delete'>): Promise<void>;
    /**
     * Update the realtime config in schema definition
     */
    private updateSchemaRealtimeConfig;
    /**
     * Set replica identity to FULL for a table (enables old values on UPDATE/DELETE)
     */
    setReplicaIdentityFull(collectionName: string): Promise<void>;
    /**
     * Get realtime config for a collection
     */
    getCollectionConfig(collectionName: string): RealtimeConfig | undefined;
    /**
     * Check if a collection has realtime enabled
     */
    isCollectionEnabled(collectionName: string): boolean;
    /**
     * Get list of enabled collections with their configs
     */
    getEnabledCollections(): Array<{
        collection: string;
        config: RealtimeConfig;
    }>;
    /**
     * Reload collection configs from database and sync publication
     * @param collectionNames - Optional list of collection names to reload. If not provided, reloads all.
     */
    reloadCollections(collectionNames?: string[]): Promise<void>;
    /**
     * Restart the replication stream to pick up publication changes
     * PostgreSQL logical replication doesn't dynamically detect publication changes,
     * so we need to disconnect and reconnect the stream.
     */
    private restartReplicationStream;
    /**
     * Load realtime config for specific collections only
     */
    private loadSpecificCollections;
    /**
     * Sync publication for specific collections only
     */
    private syncSpecificCollections;
    /**
     * Get service status
     */
    getStatus(): {
        initialized: boolean;
        connected: boolean;
        walAvailable: boolean;
        isWalLeader: boolean;
        enabledCollections: Array<{
            collection: string;
            config: RealtimeConfig;
        }>;
        publicationName: string;
        slotName: string;
    };
    /**
     * Cleanup resources on shutdown
     */
    shutdown(): Promise<void>;
    /**
     * Drop replication slot (use with caution - only for cleanup)
     */
    dropReplicationSlot(): Promise<void>;
    /**
     * Drop publication (use with caution - only for cleanup)
     */
    dropPublication(): Promise<void>;
}
declare global {
    var __baasix_realtimeService: RealtimeService | undefined;
}
declare const realtimeService: RealtimeService;
export default realtimeService;
//# sourceMappingURL=RealtimeService.d.ts.map