import { HGrid, HDict, HRef } from 'haystack-core';
import { WatchApis } from './WatchApis';
import { Subject, SubjectChangedEventHandler } from './Subject';
import { ClientServiceConfig } from '../ClientServiceConfig';
/**
 * A linger timeout in milliseconds.
 *
 * If a watch doesn't have any data to watch, a delay is made
 * before the watch is closed.
 */
export declare const LINGER_TIMEOUT_MS = 10000;
/**
 * A watch subject that uses a mutex to ensure all network calls
 * are mutally exclusive and sequential.
 */
export declare class ApiSubject implements Subject {
    #private;
    /**
     * Construct a new watch API subject.
     *
     * @param apis The watch APIs.
     * @param serviceConfig The service configuration.
     * @param pollRate The poll rate.
     */
    constructor(apis: WatchApis, serviceConfig: ClientServiceConfig, pollRate: number);
    /**
     * @returns The watch's grid instance.
     */
    get grid(): HGrid;
    /**
     * @returns The display name for the subject.
     */
    get display(): string;
    /**
     * @returns The watch id.
     */
    get watchId(): string;
    /**
     * @returns True if the watch is currently open.
     */
    isOpen(): boolean;
    /**
     * Add records to observe.
     *
     * @param ids The ids to add.
     */
    add(ids: string[]): Promise<void>;
    /**
     * Add the ids.
     *
     * @param ids The ids to add.
     */
    private addIds;
    /**
     * Add the dicts to the subject's grid.
     *
     * @param toAdd The dicts to add.
     */
    private addDictsToGrid;
    /**
     * Increment the dict reference count.
     *
     * @param toAdd The dicts to have their reference count incremented.
     */
    private incrementDictsCount;
    /**
     * Open a new watch.
     *
     * @param ids The ids to watch.
     * @returns The grid from the watch open response.
     */
    private open;
    /**
     * Attempt to reopen a watch.
     */
    private reopen;
    /**
     * Remove records to watch.
     *
     * This is called to stop watching records.
     *
     * @param ids The ids to remove.
     */
    remove(ids: string[]): Promise<void>;
    /**
     * Decrement and possible remove an id from a watch's grid.
     *
     * @param id The id to remove
     * @returns True if the id has been removed.
     */
    private decrementAndRemoveDictFromGrid;
    /**
     * Register a callback for changed events.
     *
     * @param callback The callback used for changed events.
     */
    on(callback: SubjectChangedEventHandler): void;
    /**
     * Unregister the callback for changed events.
     *
     * @param callback The callback used for changed events.
     */
    off(callback: SubjectChangedEventHandler): void;
    /**
     * Poll the watch and update the watch's grid.
     */
    poll(): Promise<void>;
    /**
     * Used to manually trigger a watch update.
     *
     * @param grid A grid of dicts to update.
     */
    update(grid: HGrid): Promise<void>;
    /**
     * Poll the watch and update the watch's grid.
     *
     * @param getUpdatedRecords Optional function used to get the updated records.
     */
    private doUpdate;
    /**
     * Return true if the dicts can trigger an update event for a watch.
     *
     * @param curDict The current dict.
     * @param newDict The new dict.
     * @returns True if an update can be triggered.
     */
    static canUpdate(curDict: HDict, newDict: HDict): boolean;
    /**
     * Update an existing dict with the new dict and return the changes
     * or undefined if none are detected.
     *
     * @param curDict The dict to be updated.
     * @param newDict The new dict.
     * @param generateEvent If true then event information will be generated as
     * the dicts are updated.
     * @returns The changes detected or undefined for no changes.
     */
    private static updateDict;
    /**
     * Completely refresh the watch.
     */
    refresh(): Promise<void>;
    /**
     * Close the watch.
     */
    private close;
    /**
     * Close the server side watch if nothing is being observed.
     */
    checkClose: () => Promise<void>;
    /**
     * Return a record via its id or undefined if it can't be found.
     *
     * @param id The id to record to get.
     * @returns The dict or undefined if it can't be found.
     */
    get(id: string | HRef): HDict | undefined;
    /**
     * @returns The subject's poll rate.
     */
    get pollRate(): number;
    /**
     * Set a poll rate.
     *
     * @param pollRate The new poll rate.
     */
    set pollRate(pollRate: number);
    /**
     * Inspect the subject.
     */
    inspect(): void;
    /**
     * Restart the watch's poll timer.
     */
    private restartPollTimer;
    /**
     * Stop the watch's poll timer.
     */
    private stopPollTimer;
    /**
     * Restart the watch's linger timer.
     *
     * If a watch is empty then a linger will wait a period of
     * time before shutting down the server side watch.
     */
    private restartLingerTimer;
    /**
     * Stop the watch's linger timer.
     */
    private stopLingerTimer;
}
