import { Logger } from '../../utils/index.js';
import { BaseTelegramClient } from '../base.js';
import { PendingUpdate, PendingUpdateContainer, UpdatesManagerParams } from './types.js';
import { AsyncLock, ConditionVariable, Deque, LruSet, timers } from '@fuman/utils';
import { tl } from '../../tl/index.js';
import { EarlyTimer } from '../../utils/early-timer.js';
import { SortedArray } from '../../utils/sorted-array.js';
import { PeersIndex } from '../types/peers/peers-index.js';
export declare class UpdatesManager {
    readonly client: BaseTelegramClient;
    readonly params: UpdatesManagerParams;
    updatesLoopActive: boolean;
    updatesLoopCv: ConditionVariable;
    postponedTimer: EarlyTimer;
    hasTimedoutPostponed: boolean;
    pendingUpdateContainers: SortedArray<PendingUpdateContainer>;
    pendingPtsUpdates: SortedArray<PendingUpdate>;
    pendingPtsUpdatesPostponed: SortedArray<PendingUpdate>;
    pendingQtsUpdates: SortedArray<PendingUpdate>;
    pendingQtsUpdatesPostponed: SortedArray<PendingUpdate>;
    pendingUnorderedUpdates: Deque<PendingUpdate>;
    noDispatchEnabled: boolean;
    noDispatchMsg: Map<number, Set<number>>;
    noDispatchPts: Map<number, Set<number>>;
    noDispatchQts: Set<number>;
    _recentlyDispatchedCommonMsgs: LruSet<number>;
    lock: AsyncLock;
    pts?: number;
    qts?: number;
    date?: number;
    seq?: number;
    oldPts?: number;
    oldQts?: number;
    oldDate?: number;
    oldSeq?: number;
    catchingUp: boolean;
    catchUpOnStart: boolean;
    cpts: Map<number, number>;
    cptsMod: Map<number, number>;
    channelDiffTimeouts: Map<number, timers.Timer>;
    channelsOpened: Map<number, number>;
    log: Logger;
    private _onCatchingUp;
    private _channelPtsLimit;
    keepAliveInterval?: timers.Interval;
    constructor(client: BaseTelegramClient, params?: UpdatesManagerParams);
    onCatchingUp(handler: (catchingUp: boolean) => void): void;
    destroy(): void;
    notifyLoggedIn(): void;
    notifyLoggedOut(): void;
    prepare(): Promise<void>;
    private _onKeepAlive;
    /**
     * Start updates loop.
     *
     * You must first call {@link enableUpdatesProcessing} to use this method.
     *
     * It is recommended to use this method in callback to {@link start},
     * or otherwise make sure the user is logged in.
     *
     * > **Note**: If you are using {@link UpdatesManagerParams.catchUp} option,
     * > catching up will be done in background, you can't await it.
     * > Instead, listen for the `updating` and `connected` connection state events.
     */
    startLoop(): Promise<void>;
    /**
     * **ADVANCED**
     *
     * Manually stop updates loop.
     * Usually done automatically when stopping the client with {@link close}
     */
    stopLoop(): void;
    /**
     * Catch up with the server by loading missed updates.
     *.
     * > **Note**: In case the storage was not properly
     * > closed the last time, "catching up" might
     * > result in duplicate updates.
     */
    catchUp(): void;
    handleClientUpdate(update: tl.TypeUpdates, noDispatch?: boolean): void;
    handleUpdate(update: tl.TypeUpdates): void;
    /**
     * **ADVANCED**
     *
     * Notify the updates manager that some channel was "opened".
     * Channel difference for "opened" channels will be fetched on a regular basis.
     * This is a low-level method, prefer using {@link openChat} instead.
     *
     * Channel must be resolve-able with `resolvePeer` method (i.e. be in cache);
     * base chat PTS must either be passed (e.g. from {@link Dialog}), or cached in storage.
     *
     * @param channelId  Bare ID of the channel
     * @param pts  PTS of the channel, if known (e.g. from {@link Dialog})
     * @returns `true` if the channel was opened for the first time, `false` if it is already opened
     */
    notifyChannelOpened(channelId: number, pts?: number): boolean;
    /**
     * **ADVANCED**
     *
     * Notify the updates manager that some channel was "closed".
     * Basically the opposite of {@link notifyChannelOpened}.
     * This is a low-level method, prefer using {@link closeChat} instead.
     *
     * @param channelId  Bare channel ID
     * @returns `true` if the chat was closed for the last time, `false` otherwise
     */
    notifyChannelClosed(channelId: number): boolean;
    _fetchUpdatesState(): Promise<void>;
    _loadUpdatesStorage(): Promise<void>;
    _saveUpdatesStorage(save?: boolean): Promise<void>;
    _addToNoDispatchIndex(updates?: tl.TypeUpdates): void;
    _fetchMissingPeers(upd: tl.TypeUpdate, peers: PeersIndex, fromDifference?: boolean): Promise<Set<number>>;
    _storeMessageReferences(msg: tl.TypeMessage): Promise<void>;
    _fetchChannelDifference(channelId: number, fallbackPts?: number): Promise<boolean>;
    _fetchChannelDifferenceLater(requestedDiff: Map<number, Promise<void>>, channelId: number, fallbackPts?: number): void;
    _fetchChannelDifferenceViaUpdate(channelId: number, pts?: number): void;
    _fetchDifference(requestedDiff: Map<number, Promise<void>>): Promise<void>;
    _fetchDifferenceLater(requestedDiff: Map<number, Promise<void>>): void;
    _onUpdate(pending: PendingUpdate, requestedDiff: Map<number, Promise<void>>, postponed?: boolean, unordered?: boolean): Promise<void>;
    _loop(): Promise<void>;
}
