/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { TypedEventEmitter } from "@fluid-internal/client-utils";
import type { ISummarizerEvents, SummarizerStopReason } from "@fluidframework/container-runtime-definitions/internal";
import { IDisposable, ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
import { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
import { type ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
import type { IEnqueueSummarizeOptions, IOnDemandSummarizeOptions, IRefreshSummaryAckOptions, ISubmitSummaryOptions, ISummarizeHeuristicData, ISummarizerRuntime, ISummaryCancellationToken, ISummaryConfiguration, SubmitSummaryResult } from "../summarizerTypes.js";
import { IClientSummaryWatcher, SummaryCollection } from "../summaryCollection.js";
import { SummarizeResultBuilder } from "./summaryResultBuilder.js";
import type { EnqueueSummarizeResult, ISummarizeResults } from "./summaryResultTypes.js";
/**
 * An instance of RunningSummarizer manages the heuristics for summarizing.
 * Until disposed, the instance of RunningSummarizer can assume that it is
 * in a state of running, meaning it is connected and initialized.  It keeps
 * track of summaries that it is generating as they are broadcast and acked/nacked.
 * This object is created and controlled by Summarizer object.
 */
export declare class RunningSummarizer extends TypedEventEmitter<ISummarizerEvents> implements IDisposable {
    private readonly summaryWatcher;
    private readonly configuration;
    private readonly submitSummaryCallback;
    private readonly refreshLatestSummaryAckCallback;
    private readonly heuristicData;
    private readonly summaryCollection;
    private readonly cancellationToken;
    private readonly stopSummarizerCallback;
    private readonly runtime;
    static start(logger: ITelemetryBaseLogger, summaryWatcher: IClientSummaryWatcher, configuration: ISummaryConfiguration, submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>, refreshLatestSummaryAckCallback: (options: IRefreshSummaryAckOptions) => Promise<void>, heuristicData: ISummarizeHeuristicData, summaryCollection: SummaryCollection, cancellationToken: ISummaryCancellationToken, stopSummarizerCallback: (reason: SummarizerStopReason) => void, runtime: ISummarizerRuntime): Promise<RunningSummarizer>;
    get disposed(): boolean;
    private stopping;
    private _disposed;
    private summarizingLock;
    private tryWhileSummarizing;
    private readonly pendingAckTimer;
    private heuristicRunner?;
    private readonly generator;
    private readonly mc;
    private enqueuedSummary;
    private summarizeCount;
    private totalSuccessfulAttempts;
    private initialized;
    private readonly runtimeListener;
    /**
     * The maximum number of summary attempts to do when submit summary fails.
     */
    private readonly maxAttemptsForSubmitFailures;
    /**
     * These are necessary to store outside of methods because of the logic around runnning a lastSummary.
     * We want the lastSummary to also be captured as "all attempts failed".
     */
    private lastSummarizeFailureEventProps;
    private constructor();
    private handleSummaryAck;
    private readonly refreshLatestSummaryAckAndHandleError;
    /**
     * Responsible for receiving and processing all the summary acks.
     * It starts processing ACKs after the one for the summary this client loaded from (initialSequenceNumber). Any
     * ACK before that is not interesting as it will simply be ignored.
     *
     * @param referenceSequenceNumber - The referenceSequenceNumber of the summary from which to start processing
     * acks.
     */
    private processIncomingSummaryAcks;
    dispose(): void;
    /**
     * RunningSummarizer's logger includes the sequenced index of the current summary on each event.
     * If some other Summarizer code wants that event on their logs they can get it here,
     * but only if they're logging about that same summary.
     * @param summaryOpRefSeq - RefSeq number of the summary op, to ensure the log correlation will be correct
     */
    tryGetCorrelatedLogger: (summaryOpRefSeq: number) => ITelemetryLoggerExt | undefined;
    /**
     * We only want a single heuristic runner micro-task (will provide better optimized grouping of ops)
     */
    private heuristicRunnerMicroTaskExists;
    handleOp(op: ISequencedDocumentMessage, runtimeMessage: boolean): void;
    /**
     * Can the given op trigger a summary?
     * # Currently always prevents summaries for Summarize and SummaryAck/Nack ops
     * @param op - op to check
     * @returns true if this op can trigger a summary
     */
    private opCanTriggerSummary;
    private nonRuntimeOpCanTriggerSummary;
    waitStop(allowLastSummary: boolean): Promise<void>;
    private waitStart;
    private beforeSummaryAction;
    private afterSummaryAction;
    /**
     * Runs single summary action that prevents any other concurrent actions.
     * Assumes that caller checked upfront for lack of concurrent action (this.summarizingLock)
     * before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.
     * @param before - set of instructions to run before running the action.
     * @param action - action to perform.
     * @param after - set of instructions to run after running the action.
     * @returns The result of the action.
     */
    private lockedSummaryAction;
    /**
     * Runs single summarize attempt
     * @param summarizeProps - props to log with each telemetry event associated with this attempt
     * @param options - summary options
     * @param cancellationToken - cancellation token to use to be able to cancel this summary, if needed
     * @param resultsBuilder - optional, result builder to use.
     * @param isLastSummary - optional, is the call to this method for a last summary when shutting down the summarizer?
     * @returns ISummarizeResult - result of running a summary.
     */
    private trySummarizeOnce;
    /**
     * Heuristics summarize attempt.
     */
    private trySummarize;
    /**
     * Tries to summarize with retries where retry is based on the failure params.
     * For example, summarization may be retried for failures with "retryAfterSeconds" param.
     */
    private trySummarizeWithRetries;
    /**
     * Attempts to generate a summary on demand with retries in case of failures. The retry logic is the same
     * as heuristics based summaries.
     */
    private summarizeOnDemandWithRetries;
    /**
     *{@inheritdoc (ISummarizer:interface).summarizeOnDemand}
     */
    summarizeOnDemand(options: IOnDemandSummarizeOptions, resultsBuilder?: SummarizeResultBuilder): ISummarizeResults;
    /**
     *{@inheritdoc (ISummarizer:interface).enqueueSummarize}
     */
    enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult;
    private tryRunEnqueuedSummary;
    private disposeEnqueuedSummary;
}
//# sourceMappingURL=runningSummarizer.d.ts.map