"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var igd_productdata_1 = require("@intelligentgraphics/igd.productdata");
var Gfx = require("@intelligentgraphics/igd.gfxservice");
var CatalogManager_1 = require("./CatalogManager");
var File_1 = require("./File");
var ProductDataManager_1 = require("./ProductDataManager");
var Backend = /** @class */ (function (_super) {
    tslib_1.__extends(Backend, _super);
    function Backend() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Backend.prototype.initializeManagers = function (_a, connectionManager) {
        var catalog = _a.catalog, dispatcherId = _a.dispatcherId;
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var settings, data, catalogManager, gfxService, _b;
            return tslib_1.__generator(this, function (_c) {
                switch (_c.label) {
                    case 0:
                        settings = catalog.Settings;
                        return [4 /*yield*/, File_1.loadData(settings)];
                    case 1:
                        data = _c.sent();
                        return [4 /*yield*/, CatalogManager_1.CatalogManager.Create({
                                file: data,
                            })];
                    case 2:
                        catalogManager = _c.sent();
                        return [4 /*yield*/, connectionManager.ensureConnection("GFX", dispatcherId, function () {
                                if (settings.Gfx.session) {
                                    return Gfx.Service.WithSession(settings.Gfx);
                                }
                                return Promise.resolve(new Gfx.Service(settings.Gfx));
                            })];
                    case 3:
                        gfxService = _c.sent();
                        _b = {
                            catalogManager: catalogManager
                        };
                        return [4 /*yield*/, ProductDataManager_1.createProductDataManager({
                                file: data,
                                gfxService: gfxService,
                            })];
                    case 4: return [2 /*return*/, (_b.productManager = _c.sent(),
                            _b)];
                }
            });
        });
    };
    return Backend;
}(igd_productdata_1.Backend));
exports.Backend = Backend;
