/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { assert, Deferred } from "@fluidframework/core-utils/internal";
export class SummarizeResultBuilder {
    constructor() {
        this.summarySubmitted = new Deferred();
        this.summaryOpBroadcasted = new Deferred();
        this.receivedSummaryAckOrNack = new Deferred();
    }
    /**
     * Fails one or more of the three results as per the passed params.
     * If submit fails, all three results fail.
     * If op broadcast fails, only op broadcast result and ack nack result fails.
     * If ack nack fails, only ack nack result fails.
     */
    fail(message, error, submitFailureResult, nackSummaryResult) {
        assert(!this.receivedSummaryAckOrNack.isCompleted, 0x25e /* "no reason to call fail if all promises have been completed" */);
        const result = {
            success: false,
            message,
            data: undefined,
            error,
        };
        // Note that if any of these are already resolved, it will be a no-op. For example, if ack nack failed but
        // submit summary and op broadcast has already been resolved as passed, only ack nack result will get modified.
        this.summarySubmitted.resolve({ ...result, data: submitFailureResult });
        this.summaryOpBroadcasted.resolve(result);
        this.receivedSummaryAckOrNack.resolve({ ...result, data: nackSummaryResult });
    }
    build() {
        return {
            summarySubmitted: this.summarySubmitted.promise,
            summaryOpBroadcasted: this.summaryOpBroadcasted.promise,
            receivedSummaryAckOrNack: this.receivedSummaryAckOrNack.promise,
        };
    }
}
//# sourceMappingURL=summaryResultBuilder.js.map