import { __awaiter, __generator, __read, __spread } from "tslib";
import { noop } from "@intelligentgraphics/ig.utilities";
export var executeDeleteOperation = function (comId, articleQuery, scheduler, productDataManager) { return __awaiter(void 0, void 0, void 0, function () {
    var deleteTargets, results;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                deleteTargets = __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 __awaiter(void 0, void 0, void 0, function () {
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, productDataManager.removeArticle(article.comId).catch(noop)];
            case 1:
                _a.sent();
                return [2 /*return*/, {
                        type: "delete",
                        comId: article.comId,
                    }];
        }
    });
}); };
