import { __assign, __read, __spread } from "tslib";
import { BackendRegistry, createSessionAPI } from "../Session";
import { createServiceManager } from "../ServiceManager";
import { createArticleState } from "../ArticleState";
import { createArticleQuery } from "./ArticleQuery";
import { createArticleManager } from "./ArticleManager";
import { createNotificationCenter } from "../NotificationCenter";
import { createConnectionManager } from "../ConnectionManager";
import { createArticleRegistry } from "../ArticleRegistry";
import { createProjectManager } from "../ProjectManager";
import { createOperationResultHandler } from "../OperationResultHandler";
import { createHooks } from "../Hooks";
import { createSourceRegistry } from "../SourceRegistry";
import { createLocalizationManager } from "../LocalizationManager";
import { NoopApplicationState } from "../NoopApplicationState";
import { createScheduler } from "../Scheduler";
export var 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 : _c;
    var hooks = createHooks();
    var connectionManager = createConnectionManager();
    var notificationCenter = createNotificationCenter();
    var localizationManager = createLocalizationManager({
        language: language,
        currency: currency,
        locale: locale,
    }, notificationCenter);
    var serviceManager = createServiceManager(BackendRegistry);
    var articleState = createArticleState();
    var articleQuery = createArticleQuery(articleState);
    var scheduler = createScheduler(articleQuery);
    var articleRegistry = createArticleRegistry(serviceManager, articleState);
    var operationResultHandler = createOperationResultHandler(articleRegistry, articleQuery, notificationCenter, hooks);
    var articleManager = createArticleManager(serviceManager, articleState, articleQuery, operationResultHandler, applicationState);
    var sourceRegistry = createSourceRegistry(serviceManager, articleQuery, scheduler);
    var projectManager = createProjectManager(serviceManager, articleQuery, articleManager, operationResultHandler, hooks, sourceRegistry, connectionManager, localizationManager);
    var services = {
        scheduler: scheduler,
        notificationCenter: notificationCenter,
        backendManager: 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, __spread([mainComId], args));
    }; };
    var getProductDataManager = withMainArticleComId(serviceManager.getProductDataManagerForComId);
    var getCatalogManager = withMainArticleComId(serviceManager.getCatalogManagerForComId);
    var getOperator = withMainArticleComId(serviceManager.getOperatorForComId);
    var getConfigurationService = withMainArticleComId(serviceManager.getConfigurationServiceForComId);
    return __assign(__assign({}, 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 });
};
