import type { TAddress, TClientId, TNetworkId_S, TNetworkToken_S, TProcessAddress } from '@flux/shared/types';
import { NetworkAuthorityRedisSortedSet } from '@flux/mesh/store/redis/network-authority';
import { NetworkAgentRedisService } from '@flux/mesh/store/redis/network-agent';
import type { TGlobalChannel } from '../global-channel/global-channel-pubsub.class';
/**
 * Singleton function to get the Redis connection.
 *
 * @param { string } [connectionString] - Optional connection string override
 *
 * @returns { RedisConnection } The singleton Redis connection
 */
export declare const getMeshRedisConnection: (connectionString?: string) => RedisConnection;
export type MessageCallback = (message: string, channel?: string) => unknown;
export declare class RedisConnection {
    private readonly _optionsOrURL;
    private readonly cacheClient;
    private readonly pubSub;
    readonly networkAuthoritySet: NetworkAuthorityRedisSortedSet;
    readonly networkAgentRedisService: NetworkAgentRedisService;
    readonly hash: {
        sadd: (key: Bun.RedisClient.KeyLike, ...members: string[]) => Promise<number>;
        hset: {
            (key: Bun.RedisClient.KeyLike, fields: Record<string | number, Bun.RedisClient.KeyLike | number>): Promise<number>;
            (key: Bun.RedisClient.KeyLike, field: Bun.RedisClient.KeyLike, value: Bun.RedisClient.KeyLike, ...rest: Bun.RedisClient.KeyLike[]): Promise<number>;
        };
        smembers: (key: Bun.RedisClient.KeyLike) => Promise<string[]>;
        srem: (key: Bun.RedisClient.KeyLike, ...members: string[]) => Promise<number>;
        scard: (key: Bun.RedisClient.KeyLike) => Promise<number>;
        del: (...keys: Bun.RedisClient.KeyLike[]) => Promise<number>;
        hincrby: (key: Bun.RedisClient.KeyLike, field: string, increment: string | number) => Promise<number>;
        hmget: {
            (key: Bun.RedisClient.KeyLike, ...fields: string[]): Promise<Array<string | null>>;
            (key: Bun.RedisClient.KeyLike, fields: string[]): Promise<Array<string | null>>;
        };
        expire: (key: Bun.RedisClient.KeyLike, seconds: number) => Promise<number>;
    };
    constructor(_optionsOrURL: string | {
        name?: string;
        url: string;
    });
    /**
     * Publishes a websocket channel event to all processes, except the one specified.
     */
    publishWebsocketChannelEvent(skipProcessAddress: TProcessAddress, channel: TGlobalChannel, message: string): Promise<void>;
    /**
     * Subscribes to websocket channel events from all processes.
     */
    subscribeWebsocketChannelEvent(callback: (channel: TGlobalChannel, skipProcessAddress: TProcessAddress, message: string) => unknown): Promise<void>;
    /**
     * Publishes the current set of valid token values for a network.
     * Called by the portal whenever tokens are created, rotated, or deleted.
     */
    publishNetworkTokenEvent(networkId: TNetworkId_S, tokens: TNetworkToken_S[]): Promise<void>;
    /**
     * Subscribes to network token update events.
     * The mesh calls this to keep its local token cache in sync.
     */
    subscribeToNetworkTokenEvents(callback: (networkId: TNetworkId_S, tokens: TNetworkToken_S[]) => void): void;
    /**
     * Persists the current set of valid token values for a network into a
     * Redis Set so that mesh processes can bootstrap their local caches after
     * a cold start (i.e. before any pub/sub event has been received).
     *
     * The key format is: `:flux:network-tokens/{networkId}/values`.
     *
     * Called by the portal on every token mutation alongside
     * {@link publishNetworkTokenEvent}.
     */
    setNetworkTokenValues(networkId: TNetworkId_S, tokens: TNetworkToken_S[]): Promise<void>;
    /**
     * Reads the set of valid token values for a network from the persistent
     * Redis Set written by the portal.
     *
     * Used by {@link NetworkTokenCache} for cold-start bootstrapping.
     */
    getNetworkTokenValues(networkId: TNetworkId_S): Promise<TNetworkToken_S[]>;
    publishCustom(subChannel: 'kick-client-agent' | 'kick-client-authority', destinationProcessAddress: TProcessAddress, message: string): Promise<number>;
    subscribeToCustom(subChannel: 'kick-client-agent' | 'kick-client-authority', destinationProcessAddress: TProcessAddress, callback: (data: string) => void): void;
    /**
     * Publishes a message directly to an address.
     */
    directPublish(address: TAddress | TProcessAddress, message: string): Promise<void>;
    /**
     * Subscribes to messages on a Redis channel.
     */
    subscribe(channelId: TProcessAddress | TClientId, callback: MessageCallback): void;
    /**
     * Unsubscribes from messages on a Redis channel.
     */
    unsubscribe(channelId: string, callback: MessageCallback): void;
    /**
     * Subscribes to data packets published on a specific network channel.
     * Invokes the callback with the raw data string from each packet.
     */
    subscribeToNetworkChannel(networkId: string, channelName: string, callback: (clientId: TClientId, data: string) => void): void;
    /**
     * Unsubscribes a callback from data packets on a specific network channel.
     */
    unsubscribeFromNetworkChannel(networkId: string, channelName: string, callback: (clientId: TClientId, data: string) => void): void;
    /**
     * Marks the given address as connected in Redis.
     */
    setConnected(address: string): Promise<void>;
    /**
     * Marks the given address as disconnected in Redis.
     */
    setDisconnected(_address: string): Promise<void>;
    /**
     * Disconnects the Redis cache and pub/sub.
     *
     * @returns { Promise<void> }
     */
    disconnect(): Promise<void>;
}
