"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ig_utilities_1 = require("@intelligentgraphics/ig.utilities");
exports.executeDeleteOperation = function (comId, articleQuery, scheduler, productDataManager) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
    var deleteTargets, results;
    return tslib_1.__generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                deleteTargets = tslib_1.__spread([
                    comId
                ], articleQuery.getDeepArticleChildren(comId));
                return [4 /*yield*/, Promise.all(deleteTargets.map(function (comId) {
                        var article = articleQuery.getArticleByComId(comId);
                        if (article === undefined) {
                            return Promise.resolve();
                        }
                        return scheduler.queueDeleteOperation(article.comId, function () {
                            return deleteArticle(article, productDataManager);
                        });
                    }))];
            case 1:
                results = _a.sent();
                return [2 /*return*/, results.filter(Boolean)];
        }
    });
}); };
var deleteArticle = function (article, productDataManager) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
    return tslib_1.__generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, productDataManager.removeArticle(article.comId).catch(ig_utilities_1.noop)];
            case 1:
                _a.sent();
                return [2 /*return*/, {
                        type: "delete",
                        comId: article.comId,
                    }];
        }
    });
}); };
