/**
 * @fileoverview added by tsickle
 * Generated from: common/activity-reporter/activity-reporter.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { __awaiter, __generator, __values } from "tslib";
/*!
 * Copyright 2020 VMware, Inc.
 * SPDX-License-Identifier: BSD-2-Clause
 */
/**
 * Expresses the contract between a activity status and the UI displaying a loading message, reporting
 * success or errors
 * Currently, only one concurrent activity is supported.
 * @abstract
 */
var /**
 * Expresses the contract between a activity status and the UI displaying a loading message, reporting
 * success or errors
 * Currently, only one concurrent activity is supported.
 * @abstract
 */
ActivityReporter = /** @class */ (function () {
    /**
     * Creates this reporter with the performer that it will use to monitor events.
     */
    function ActivityReporter(promiseResolver) {
        this.promiseResolver = promiseResolver;
    }
    /**
     * Monitors a promise that returns an entity using {@link ActivityPromiseResolver.monitorActivity}.
     */
    /**
     * Monitors a promise that returns an entity using {\@link ActivityPromiseResolver.monitorActivity}.
     * @template T
     * @param {?} activityResolutionPromise
     * @return {?}
     */
    ActivityReporter.prototype.monitorGet = /**
     * Monitors a promise that returns an entity using {\@link ActivityPromiseResolver.monitorActivity}.
     * @template T
     * @param {?} activityResolutionPromise
     * @return {?}
     */
    function (activityResolutionPromise) {
        return __awaiter(this, void 0, void 0, function () {
            var performer, response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.startActivity();
                        performer = (/** @type {?} */ (this.promiseResolver));
                        return [4 /*yield*/, performer.resolveActivity(activityResolutionPromise)];
                    case 1:
                        response = _a.sent();
                        if (response.response.error) {
                            this.reportError(response.response.error);
                        }
                        else {
                            this.reportSuccess(response.response.success);
                        }
                        return [2 /*return*/, response.object];
                }
            });
        });
    };
    /**
     * Monitors a promise that returns many entities using {@link ActivityPromiseResolver.monitorActivities}.
     */
    /**
     * Monitors a promise that returns many entities using {\@link ActivityPromiseResolver.monitorActivities}.
     * @template T
     * @param {?} activityResolutionPromises
     * @return {?}
     */
    ActivityReporter.prototype.monitorGetAll = /**
     * Monitors a promise that returns many entities using {\@link ActivityPromiseResolver.monitorActivities}.
     * @template T
     * @param {?} activityResolutionPromises
     * @return {?}
     */
    function (activityResolutionPromises) {
        return __awaiter(this, void 0, void 0, function () {
            var performer, response, returnValue, response_1, response_1_1, item;
            var e_1, _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        this.startActivity();
                        performer = (/** @type {?} */ (this.promiseResolver));
                        return [4 /*yield*/, performer.resolveActivities(activityResolutionPromises)];
                    case 1:
                        response = _b.sent();
                        returnValue = response.map((/**
                         * @param {?} item
                         * @return {?}
                         */
                        function (item) { return item.object; }));
                        if (response.length) {
                            try {
                                for (response_1 = __values(response), response_1_1 = response_1.next(); !response_1_1.done; response_1_1 = response_1.next()) {
                                    item = response_1_1.value;
                                    if (item.response.error) {
                                        this.reportError(item.response.error);
                                        return [2 /*return*/, returnValue];
                                    }
                                }
                            }
                            catch (e_1_1) { e_1 = { error: e_1_1 }; }
                            finally {
                                try {
                                    if (response_1_1 && !response_1_1.done && (_a = response_1.return)) _a.call(response_1);
                                }
                                finally { if (e_1) throw e_1.error; }
                            }
                            this.reportSuccess(response[0].response.success);
                        }
                        return [2 /*return*/, returnValue];
                }
            });
        });
    };
    /**
     * Monitors a promise that returns an entity and posts a successMessage using {@link ActivityPromiseResolver.monitorActivity}.
     */
    /**
     * Monitors a promise that returns an entity and posts a successMessage using {\@link ActivityPromiseResolver.monitorActivity}.
     * @template T
     * @param {?} activityResolutionPromise
     * @param {?=} successMessage
     * @return {?}
     */
    ActivityReporter.prototype.monitorEdit = /**
     * Monitors a promise that returns an entity and posts a successMessage using {\@link ActivityPromiseResolver.monitorActivity}.
     * @template T
     * @param {?} activityResolutionPromise
     * @param {?=} successMessage
     * @return {?}
     */
    function (activityResolutionPromise, successMessage) {
        return __awaiter(this, void 0, void 0, function () {
            var performer, response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.startActivity();
                        performer = (/** @type {?} */ (this.promiseResolver));
                        return [4 /*yield*/, performer.resolveActivity(activityResolutionPromise, successMessage)];
                    case 1:
                        response = _a.sent();
                        if (response.response.error) {
                            this.reportError(response.response.error);
                        }
                        else {
                            this.reportSuccess(response.response.success);
                        }
                        return [2 /*return*/, response.object];
                }
            });
        });
    };
    return ActivityReporter;
}());
/**
 * Expresses the contract between a activity status and the UI displaying a loading message, reporting
 * success or errors
 * Currently, only one concurrent activity is supported.
 * @abstract
 */
export { ActivityReporter };
if (false) {
    /**
     * @type {?}
     * @private
     */
    ActivityReporter.prototype.promiseResolver;
    /**
     * @abstract
     * @return {?}
     */
    ActivityReporter.prototype.startActivity = function () { };
    /**
     * Override this method to provide custom error reporting behavior.
     *
     * @abstract
     * @param {?} errorText The text to display in the error alert.
     * @return {?}
     */
    ActivityReporter.prototype.reportError = function (errorText) { };
    /**
     * Override this method to provide custom success reporting behavior.
     *
     * @abstract
     * @param {?} successMessage A message to display to the user.
     * @return {?}
     */
    ActivityReporter.prototype.reportSuccess = function (successMessage) { };
}
//# sourceMappingURL=data:application/json;base64, 