/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { TypedEventEmitter } from "@fluid-internal/client-utils";
import type { IDeltaManager } from "@fluidframework/container-definitions/internal";
import type { IDisposable, IEvent, ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
import { type IDocumentMessage, type ISummaryAck, type ISummaryContent, type ISummaryNack, MessageType, type ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
/**
 * Interface for summary op messages with typed contents.
 * @legacy @beta
 */
export interface ISummaryOpMessage extends ISequencedDocumentMessage {
    type: MessageType.Summarize;
    contents: ISummaryContent;
}
/**
 * Interface for summary ack messages with typed contents.
 * @legacy @beta
 */
export interface ISummaryAckMessage extends ISequencedDocumentMessage {
    type: MessageType.SummaryAck;
    contents: ISummaryAck;
}
/**
 * Interface for summary nack messages with typed contents.
 * @legacy @beta
 */
export interface ISummaryNackMessage extends ISequencedDocumentMessage {
    type: MessageType.SummaryNack;
    contents: ISummaryNack;
}
/**
 * A single summary which can be tracked as it goes through its life cycle.
 * The life cycle is: Local to Broadcast to Acked/Nacked.
 * @legacy @beta
 */
export interface ISummary {
    readonly clientId: string;
    readonly clientSequenceNumber: number;
    waitBroadcast(): Promise<ISummaryOpMessage>;
    waitAckNack(): Promise<ISummaryAckMessage | ISummaryNackMessage>;
}
/**
 * A single summary which has already been acked by the server.
 * @legacy @beta
 */
export interface IAckedSummary {
    readonly summaryOp: ISummaryOpMessage;
    readonly summaryAck: ISummaryAckMessage;
}
/**
 * Watches summaries created by a specific client.
 * @legacy @beta
 */
export interface IClientSummaryWatcher extends IDisposable {
    watchSummary(clientSequenceNumber: number): ISummary;
    waitFlushed(): Promise<IAckedSummary | undefined>;
}
/**
 * @legacy @beta
 */
export type OpActionEventName = MessageType.Summarize | MessageType.SummaryAck | MessageType.SummaryNack | "default";
/**
 * @legacy @beta
 */
export type OpActionEventListener = (op: ISequencedDocumentMessage) => void;
/**
 * @legacy @beta
 */
export interface ISummaryCollectionOpEvents extends IEvent {
    (event: OpActionEventName, listener: OpActionEventListener): any;
}
/**
 * Data structure that looks at the op stream to track summaries as they
 * are broadcast, acked and nacked.
 * It provides functionality for watching specific summaries.
 * @legacy @beta
 */
export declare class SummaryCollection extends TypedEventEmitter<ISummaryCollectionOpEvents> {
    private readonly deltaManager;
    private readonly summaryWatchers;
    private readonly pendingSummaries;
    private refreshWaitNextAck;
    private lastSummaryTimestamp;
    private maxAckWaitTime;
    private pendingAckTimerTimeoutCallback;
    private lastAck;
    get latestAck(): IAckedSummary | undefined;
    emit(event: OpActionEventName, ...args: Parameters<OpActionEventListener>): boolean;
    get opsSinceLastAck(): number;
    addOpListener(listener: () => void): void;
    removeOpListener(listener: () => void): void;
    private readonly logger;
    constructor(deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>, logger: ITelemetryBaseLogger);
    /**
     * Creates and returns a summary watcher for a specific client.
     * This will allow for local sent summaries to be better tracked.
     * @param clientId - client id for watcher
     */
    createWatcher(clientId: string): IClientSummaryWatcher;
    removeWatcher(clientId: string): void;
    setPendingAckTimerTimeoutCallback(maxAckWaitTime: number, timeoutCallback: () => void): void;
    unsetPendingAckTimerTimeoutCallback(): void;
    /**
     * Returns a promise that resolves once all pending summary ops
     * have been acked or nacked.
     */
    waitFlushed(): Promise<IAckedSummary | undefined>;
    /**
     * Returns a promise that resolves once a summary is acked that has a reference
     * sequence number greater than or equal to the passed in sequence number.
     * @param referenceSequenceNumber - reference sequence number to wait for
     * @returns The latest acked summary
     */
    waitSummaryAck(referenceSequenceNumber: number): Promise<IAckedSummary>;
    private parseContent;
    /**
     * Handler for ops; only handles ops relating to summaries.
     * @param op - op message to handle
     */
    private handleOp;
    private handleSummaryOp;
    private handleSummaryAck;
    private handleSummaryNack;
}
//# sourceMappingURL=summaryCollection.d.ts.map