import type { Server as HTTPServer } from "http";
import type { UserInfo, SocketWithAuth } from '../types/index.js';
export type CustomMessageHandler = (socket: SocketWithAuth, data: any, callback?: (response: any) => void) => void | Promise<void>;
export type RoomValidator = (socket: SocketWithAuth, roomName: string) => boolean | Promise<boolean>;
declare class SocketService {
    private io;
    private userSockets;
    private initialized;
    private redisPublisher;
    private redisSubscriber;
    private customRooms;
    private roomCreators;
    private roomOriginalCreators;
    private socketIdToUserId;
    private customMessageHandlers;
    private roomValidators;
    private static readonly ROOM_HISTORY_LIMIT;
    private roomMessageHistory;
    private get useRedis();
    /** Add / update a member in the room's member store */
    private rRoomMemberSet;
    /** Remove a member from the room's member store */
    private rRoomMemberDel;
    /** Check if a socket is in a room */
    private rRoomMemberHas;
    /** Get all members of a room as Map<socketId, meta> */
    private rRoomMembersAll;
    /** Number of members in a room */
    private rRoomMemberCount;
    /** Delete the entire room (all member keys + creator keys + history) */
    private rRoomDestroy;
    /** Get current creator socketId */
    private rCreatorGet;
    /** Set current creator socketId */
    private rCreatorSet;
    /** Delete current creator entry */
    private rCreatorDel;
    /** Get original creator userId */
    private rOriginalCreatorGet;
    /** Set original creator userId (only set once — NX) */
    private rOriginalCreatorSet;
    /** Append a message to history, trimming to ROOM_HISTORY_LIMIT */
    private rHistoryPush;
    /** Fetch all history entries for a room */
    private rHistoryGet;
    constructor();
    initialize(server: HTTPServer): Promise<void>;
    initializeRedisAdapter(): Promise<void>;
    cleanup(): Promise<void>;
    authMiddleware(socket: SocketWithAuth, next: (err?: Error) => void): Promise<void>;
    authenticateUser(decoded: any): Promise<UserInfo>;
    handleConnection(socket: SocketWithAuth): Promise<void>;
    handleSubscribe(socket: SocketWithAuth, { collection }: {
        collection: string;
    }): Promise<void>;
    handleUnsubscribe(socket: SocketWithAuth, { collection }: {
        collection: string;
    }): void;
    handleDisconnect(socket: SocketWithAuth): void;
    private handleDisconnectRoomCleanup;
    /**
     * Handle a user joining a custom room
     */
    handleRoomJoin(socket: SocketWithAuth, roomName: string, metadata?: Record<string, any>): Promise<void>;
    /**
     * Handle a user leaving a custom room
     */
    handleRoomLeave(socket: SocketWithAuth, roomName: string): Promise<void>;
    /**
     * Handle a message sent to a custom room
     */
    handleRoomMessage(socket: SocketWithAuth, roomName: string, event: string, payload: any, storeInHistory?: boolean): Promise<void>;
    /**
     * Return member list for a room. Only callable by current room members.
     * Returns userId, socketId, metadata, and whether each member is the room creator.
     */
    handleRoomMembers(socket: SocketWithAuth, roomName: string): Promise<Array<{
        socketId: string;
        userId: string | number;
        isCreator: boolean;
        metadata: Record<string, any>;
    }>>;
    /**
     * Kick a user from a custom room. Only the room creator may do this.
     * All sockets belonging to the target user that are in the room will be removed.
     */
    handleRoomKick(socket: SocketWithAuth, roomName: string, targetUserId: string | number): Promise<void>;
    /**
     * Handle custom events with registered handlers
     */
    handleCustomEvent(socket: SocketWithAuth, event: string, payload: any, callback?: (response: any) => void): Promise<void>;
    /**
     * Register a custom message handler for a specific event
     * Can be used by extensions to handle custom socket events
     *
     * @example
     * socketService.registerMessageHandler("game:move", async (socket, data, callback) => {
     *   // Handle game move logic
     *   callback?.({ status: "success", result: { ... } });
     * });
     */
    registerMessageHandler(event: string, handler: CustomMessageHandler): void;
    /**
     * Unregister a custom message handler
     */
    unregisterMessageHandler(event: string): void;
    /**
     * Register a validator for room join requests
     * Validator is called when a user tries to join a room matching the pattern
     *
     * @example
     * socketService.registerRoomValidator("game:", async (socket, roomName) => {
     *   // Only allow admins to join game rooms
     *   return socket.userRole.name === "administrator";
     * });
     */
    registerRoomValidator(roomPattern: string, validator: RoomValidator): void;
    /**
     * Unregister a room validator
     */
    unregisterRoomValidator(roomPattern: string): void;
    /**
     * Broadcast a message to a custom room from server side
     *
     * @example
     * socketService.broadcastToRoom("game:123", "game:state", { players: [...] });
     */
    broadcastToRoom(roomName: string, event: string, payload: any): void;
    /**
     * Broadcast a message to all connected users
     *
     * @example
     * socketService.broadcastToAll("system:announcement", { message: "Server maintenance in 5 minutes" });
     */
    broadcastToAll(event: string, payload: any): void;
    /**
     * Send a message to a specific user (all their connected sockets)
     *
     * @example
     * socketService.sendToUser(userId, "private:message", { from: "admin", text: "Hello!" });
     */
    sendToUser(userId: string | number, event: string, payload: any): void;
    /**
     * Get list of users in a custom room (server-side utility for extensions)
     */
    getRoomMembers(roomName: string): Promise<Array<{
        socketId: string;
        userId: string | number;
        metadata: Record<string, any>;
    }>>;
    /**
     * Get count of users in a custom room
     */
    getRoomMemberCount(roomName: string): Promise<number>;
    /**
     * Check if a room exists
     */
    roomExists(roomName: string): Promise<boolean>;
    /**
     * Get all custom rooms with member counts
     */
    getCustomRooms(): Promise<Map<string, number>>;
    checkCollectionAccess(socket: SocketWithAuth, collection: string): Promise<boolean>;
    getCollectionRoom(collection: string, tenantId?: string | number): string;
    broadcastChange(collection: string, action: string, data: any, accountability?: any): void;
    /**
     * Emit workflow execution updates to connected clients
     */
    emitWorkflowExecutionUpdate(executionId: string | number, data: any): void;
    /**
     * Emit workflow execution completion
     */
    emitWorkflowExecutionComplete(executionId: string | number, data: any): void;
    getStats(): any;
}
declare global {
    var __baasix_socketService: SocketService | undefined;
}
declare const socketService: SocketService;
export default socketService;
//# sourceMappingURL=SocketService.d.ts.map