"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Session_1 = require("../Session");
var ServiceManager_1 = require("../ServiceManager");
var ArticleState_1 = require("../ArticleState");
var ArticleQuery_1 = require("./ArticleQuery");
var ArticleManager_1 = require("./ArticleManager");
var NotificationCenter_1 = require("../NotificationCenter");
var ConnectionManager_1 = require("../ConnectionManager");
var ArticleRegistry_1 = require("../ArticleRegistry");
var ProjectManager_1 = require("../ProjectManager");
var OperationResultHandler_1 = require("../OperationResultHandler");
var Hooks_1 = require("../Hooks");
var SourceRegistry_1 = require("../SourceRegistry");
var LocalizationManager_1 = require("../LocalizationManager");
var NoopApplicationState_1 = require("../NoopApplicationState");
var Scheduler_1 = require("../Scheduler");
exports.createSingleArticleSession = function (_a) {
    var _b = _a === void 0 ? {} : _a, language = _b.language, currency = _b.currency, locale = _b.locale, _c = _b.applicationState, applicationState = _c === void 0 ? NoopApplicationState_1.NoopApplicationState : _c;
    var hooks = Hooks_1.createHooks();
    var connectionManager = ConnectionManager_1.createConnectionManager();
    var notificationCenter = NotificationCenter_1.createNotificationCenter();
    var localizationManager = LocalizationManager_1.createLocalizationManager({
        language: language,
        currency: currency,
        locale: locale,
    }, notificationCenter);
    var serviceManager = ServiceManager_1.createServiceManager(Session_1.BackendRegistry);
    var articleState = ArticleState_1.createArticleState();
    var articleQuery = ArticleQuery_1.createArticleQuery(articleState);
    var scheduler = Scheduler_1.createScheduler(articleQuery);
    var articleRegistry = ArticleRegistry_1.createArticleRegistry(serviceManager, articleState);
    var operationResultHandler = OperationResultHandler_1.createOperationResultHandler(articleRegistry, articleQuery, notificationCenter, hooks);
    var articleManager = ArticleManager_1.createArticleManager(serviceManager, articleState, articleQuery, operationResultHandler, applicationState);
    var sourceRegistry = SourceRegistry_1.createSourceRegistry(serviceManager, articleQuery, scheduler);
    var projectManager = ProjectManager_1.createProjectManager(serviceManager, articleQuery, articleManager, operationResultHandler, hooks, sourceRegistry, connectionManager, localizationManager);
    var services = {
        scheduler: scheduler,
        notificationCenter: notificationCenter,
        backendManager: Session_1.BackendRegistry,
        serviceManager: serviceManager,
        articleState: articleState,
        articleQuery: articleQuery,
        articleManager: articleManager,
        connectionManager: connectionManager,
        articleRegistry: articleRegistry,
        projectManager: projectManager,
        operationResultHandler: operationResultHandler,
        hooks: hooks,
        sourceRegistry: sourceRegistry,
        localizationManager: localizationManager,
        applicationState: applicationState,
    };
    var withMainArticleComId = function (func) { return function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        var mainComId = articleQuery.getMainArticleComId();
        if (mainComId === undefined) {
            return undefined;
        }
        return func.apply(void 0, tslib_1.__spread([mainComId], args));
    }; };
    var getProductDataManager = withMainArticleComId(serviceManager.getProductDataManagerForComId);
    var getCatalogManager = withMainArticleComId(serviceManager.getCatalogManagerForComId);
    var getOperator = withMainArticleComId(serviceManager.getOperatorForComId);
    var getConfigurationService = withMainArticleComId(serviceManager.getConfigurationServiceForComId);
    return tslib_1.__assign(tslib_1.__assign({}, Session_1.createSessionAPI(services)), { getMainArticleComId: articleQuery.getMainArticleComId, getMainArticle: articleQuery.getMainArticle, changeMainArticleProperties: articleManager.changeMainArticleProperties, changeMainArticleProperty: articleManager.changeMainArticleProperty, deleteMainArticle: articleManager.deleteMainArticle, getCatalogManager: getCatalogManager,
        getProductDataManager: getProductDataManager,
        getConfigurationService: getConfigurationService,
        getOperator: getOperator });
};
