import { Obj } from "@intelligentgraphics/ig.utilities";
export const fetchArticleData = async (productDataManager, comId) => {
    const [articleId, categories, properties, sourceData, subArticles,] = await Promise.all([
        productDataManager.getArticleID(comId),
        productDataManager.getArticleCategories(comId),
        productDataManager.getArticlePropertyList(comId),
        productDataManager.getArticleCustomData !== undefined
            ? productDataManager.getArticleCustomData(comId)
            : undefined,
        productDataManager.getSubArticleIDs(comId),
    ]);
    return {
        articleId,
        categories,
        properties,
        sourceData: sourceData || {},
        subArticles,
    };
};
export const fetchArticleInfo = async (productDataManager, comId, info) => {
    const loadDynamicInfo = () => ({
        varCode: productDataManager.getArticleVariantCode(comId),
        shortText: productDataManager.getArticleShortText(comId),
        longText: productDataManager.getArticleLongText(comId),
        varText: productDataManager.getArticleVariantText(comId),
        image: productDataManager.getArticleCatalogImage(comId),
        prices: productDataManager.getArticlePrices(comId),
        name: productDataManager.getArticleName(comId),
    });
    if (info === undefined) {
        info = await Obj.loadObjectData({
            ...loadDynamicInfo(),
            programName: productDataManager.getArticleProgramName(comId),
            programId: productDataManager.getArticleProgramID(comId),
            manufacturerName: productDataManager.getArticleManufacturerName(comId),
            manufacturerId: productDataManager.getArticleManufacturerID(comId),
        });
    }
    else {
        const updatedInfo = await Obj.loadObjectData(loadDynamicInfo()).catch(() => undefined);
        info = {
            ...info,
            ...updatedInfo,
        };
    }
    return info;
};
