import { __assign } from "tslib";
export var createArticleRegistry = function (serviceManager, articleState) {
    var registerArticle = function (articleData) {
        serviceManager.setArticleSource(articleData.comId, articleData.source);
        articleState.addArticle(__assign(__assign({}, articleData), { articleNumber: articleData.articleNumber === undefined
                ? undefined
                : __assign(__assign({}, 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 }) }));
    };
    var updateArticle = function (comId, data) {
        var currentArticle = articleState.getArticleByComId(comId);
        if (currentArticle === undefined) {
            throw new Error("Can not update unknown article \"" + comId + "\"");
        }
        articleState.updateArticleProperties(comId, __assign({}, data));
        return true;
    };
    var unregisterArticle = function (comId) {
        serviceManager.deleteArticleSource(comId);
        articleState.removeArticle(comId);
    };
    return {
        executeBatch: articleState.executeBatch,
        registerArticle: registerArticle,
        unregisterArticle: unregisterArticle,
        updateArticle: updateArticle,
    };
};
