import * as tslib_1 from "tslib";
import { Backend as BaseBackend, } from "@intelligentgraphics/igd.productdata";
import * as Gfx from "@intelligentgraphics/igd.gfxservice";
import { CatalogManager } from "./CatalogManager";
import { loadData } from "./File";
import { createProductDataManager } from "./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*/, loadData(settings)];
                    case 1:
                        data = _c.sent();
                        return [4 /*yield*/, 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*/, createProductDataManager({
                                file: data,
                                gfxService: gfxService,
                            })];
                    case 4: return [2 /*return*/, (_b.productManager = _c.sent(),
                            _b)];
                }
            });
        });
    };
    return Backend;
}(BaseBackend));
export { Backend };
