import { ApiCallback, EventCallback } from './eventBus';
/**
 * Options for state-aware event subscriptions
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export interface StateAwareOptions<T> {
    /** Function to fetch the current state */
    getCurrentState: () => Promise<T> | T;
    /** Optional transform function to normalize API response to event format */
    transformState?: (state: any) => T;
    /** Optional function to determine if we should use the fetched state */
    shouldUseFetchedState?: (state: T) => boolean;
    /** Timeout for waiting for events (ms) */
    timeout?: number;
}
/**
 * Wait for an event OR get the current state if the event already happened
 * This prevents race conditions where events fire before subscription
 *
 * @param eventType - The event type to wait for
 * @param options - Options for state fetching and transformation
 * @returns Promise that resolves with either the event data or current state
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export declare function waitForOrGetState<T = ApiCallback>(eventType: string, options: StateAwareOptions<T>): Promise<T>;
/**
 * Subscribe to events with initial state, ensuring no events are missed
 *
 * @param eventType - The event type to subscribe to
 * @param callback - Callback for state updates
 * @param options - Options for initial state fetching
 * @returns Unsubscribe function
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export declare function subscribeWithInitialState<T = ApiCallback>(eventType: string, callback: EventCallback<T>, options: StateAwareOptions<T>): () => void;
/**
 * Create a state-synchronized event stream that combines initial state with events
 *
 * @param eventType - The event type for updates
 * @param stateApi - API endpoint or function to fetch current state
 * @returns Object with subscribe method and current state getter
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export declare function createStatefulEventStream<T = any>(eventType: string, stateApi: string | (() => Promise<T>)): {
    /** Get current state synchronously (may be undefined if not loaded) */
    readonly state: T | undefined;
    /** Get current state asynchronously (waits for initial load) */
    getState(): Promise<T>;
    /** Subscribe to state changes (includes initial state) */
    subscribe(callback: (state: T) => void): () => void;
    /** Refresh state from API */
    refresh(): Promise<T>;
};
/**
 * Wait for multiple events with shared state checking
 * Checks global state once to see if all conditions are already met
 *
 * @param eventTypes - Array of event types to wait for
 * @param options - Shared state checking options
 * @returns Promise that resolves when all events have occurred or state is ready
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export declare function waitForAllWithState<T = ApiCallback>(eventTypes: string[], options: StateAwareOptions<T>): Promise<T>;
/**
 * Wait for a single event with state checking (convenience overload)
 *
 * @param eventType - Single event type to wait for
 * @param options - State checking options
 * @returns Promise that resolves when event occurs or state is ready
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export declare function waitForAllWithState<T = ApiCallback>(eventType: string, options: StateAwareOptions<T>): Promise<T>;
/**
 * Create a resilient event handler that can recover from missed events
 *
 * @param eventType - Event type to handle
 * @param handler - Event handler function
 * @param recoveryStrategy - Strategy for recovering missed events
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export declare function createResilientEventHandler<T = ApiCallback>(eventType: string, handler: (data: T) => void | Promise<void>, recoveryStrategy: {
    /** API to fetch missed events or current state */
    fetchMissedEvents: () => Promise<T[]> | Promise<T>;
    /** How often to check for missed events (ms) */
    checkInterval?: number;
    /** Whether to deduplicate events by ID */
    deduplicateById?: (event: T) => string;
}): () => void;
/**
 * Pattern for handling connection state with events
 * Useful for WebSocket connections, plugin loading, etc.
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export interface ConnectionStateManager<T = any> {
    /** Current connection state */
    state: "disconnected" | "connecting" | "connected" | "error";
    /** Current data (if connected) */
    data?: T;
    /** Wait for connection to be established */
    waitForConnection(timeout?: number): Promise<T>;
    /** Subscribe to state changes */
    subscribe(callback: (state: ConnectionStateManager<T>) => void): () => void;
    /** Manually trigger reconnection */
    reconnect(): Promise<void>;
}
/**
 * Create a connection state manager that handles online/offline scenarios
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export declare function createConnectionStateManager<T = any>(config: {
    connectEvent: string;
    disconnectEvent: string;
    errorEvent?: string;
    dataEvent?: string;
    fetchInitialState: () => Promise<T>;
    reconnectDelay?: number;
}): ConnectionStateManager<T>;
/**
 * Namespace collecting all state-aware event bus utilities.
 *
 * @kosService core.event-bus
 * @kosApiLevel 11
 */
export declare const EventBusState: {
    waitForOrGetState: typeof waitForOrGetState;
    subscribeWithInitialState: typeof subscribeWithInitialState;
    createStatefulEventStream: typeof createStatefulEventStream;
    waitForAllWithState: typeof waitForAllWithState;
    createResilientEventHandler: typeof createResilientEventHandler;
    createConnectionStateManager: typeof createConnectionStateManager;
};
//# sourceMappingURL=eventBus.state.d.ts.map