export const createArticleRegistry = (serviceManager, articleState) => {
    const registerArticle = (articleData) => {
        serviceManager.setArticleSource(articleData.comId, articleData.source);
        articleState.addArticle({
            ...articleData,
            articleNumber: articleData.articleNumber === undefined
                ? undefined
                : {
                    ...articleData.articleNumber,
                    // set attachTo to undefined, since it already happened and we never need the information again
                    // (also would cause issues on restore)
                    attachTo: undefined,
                },
        });
    };
    const updateArticle = (comId, data) => {
        const currentArticle = articleState.getArticleByComId(comId);
        if (currentArticle === undefined) {
            throw new Error(`Can not update unknown article "${comId}"`);
        }
        articleState.updateArticleProperties(comId, {
            ...data,
        });
        return true;
    };
    const unregisterArticle = (comId) => {
        serviceManager.deleteArticleSource(comId);
        articleState.removeArticle(comId);
    };
    return {
        executeBatch: articleState.executeBatch,
        registerArticle,
        unregisterArticle,
        updateArticle,
    };
};
