"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
exports.createArticleRegistry = function (serviceManager, articleState) {
    var registerArticle = function (articleData) {
        serviceManager.setArticleSource(articleData.comId, articleData.source);
        articleState.addArticle(tslib_1.__assign(tslib_1.__assign({}, articleData), { articleNumber: articleData.articleNumber === undefined
                ? undefined
                : tslib_1.__assign(tslib_1.__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, tslib_1.__assign({}, data));
        return true;
    };
    var unregisterArticle = function (comId) {
        serviceManager.deleteArticleSource(comId);
        articleState.removeArticle(comId);
    };
    return {
        executeBatch: articleState.executeBatch,
        registerArticle: registerArticle,
        unregisterArticle: unregisterArticle,
        updateArticle: updateArticle,
    };
};
