import { noop } from "@intelligentgraphics/ig.utilities";
export const executeDeleteOperation = async (comId, articleQuery, scheduler, productDataManager) => {
    const deleteTargets = [
        comId,
        ...articleQuery.getDeepArticleChildren(comId),
    ];
    const results = await Promise.all(deleteTargets.map(comId => {
        const article = articleQuery.getArticleByComId(comId);
        if (article === undefined) {
            return Promise.resolve();
        }
        return scheduler.queueDeleteOperation(article.comId, () => deleteArticle(article, productDataManager));
    }));
    return results.filter(Boolean);
};
const deleteArticle = async (article, productDataManager) => {
    await productDataManager.removeArticle(article.comId).catch(noop);
    return {
        type: "delete",
        comId: article.comId,
    };
};
