"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SummarizeResultBuilder = void 0;
const internal_1 = require("@fluidframework/core-utils/internal");
class SummarizeResultBuilder {
    constructor() {
        this.summarySubmitted = new internal_1.Deferred();
        this.summaryOpBroadcasted = new internal_1.Deferred();
        this.receivedSummaryAckOrNack = new internal_1.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) {
        (0, internal_1.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,
        };
    }
}
exports.SummarizeResultBuilder = SummarizeResultBuilder;
//# sourceMappingURL=summaryResultBuilder.js.map