"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServerConfigProvider = void 0;
const extension_provider_1 = require("../../integration/extension.provider");
const content_encrypted_object_provider_1 = require("../content-encrypted-object/content-encrypted-object.provider");
const root_config_const_1 = require("./../../services/root-config/root-config.const");
const root_config_provider_1 = require("./../../services/root-config/root-config.provider");
const server_config_const_1 = require("./server-config.const");
const server_config_service_1 = require("./server-config.service");
class ServerConfigProvider extends extension_provider_1.ExtensionProvider {
    constructor(app) {
        super(server_config_const_1.SERVER_CONFIG_PROVIDER, app);
        this.app = app;
        this.requiredProviders.push(root_config_provider_1.RootConfigProvider, content_encrypted_object_provider_1.ContentEncryptedObjectProvider);
        this.services.push({ cls: server_config_service_1.ServerConfigService });
        this.objectTypes.push(server_config_const_1.SERVER_CONFIGURATION_TYPE);
        this.objectSubTypes.push(server_config_const_1.ROOT_CONFIGURATION_SERVER_CONFIGURATION_SUBTYPE);
        this.objectTrees.serverConfiguration = {
            parentNode: () => this.appCtx.getExtensionContext(root_config_const_1.ROOT_CONFIG_PROVIDER).nodes
                .rootConfiguration.value,
            treeNodeTypeId: server_config_const_1.SERVER_CONFIGURATION_TYPE.name,
            treeNodeName: server_config_const_1.SERVER_CONFIGURATION_TYPE.name,
            tree: { treeNode: {}, children: {} },
        };
    }
    async boot() {
        await super.boot();
        const service = await this.app.getService(server_config_service_1.ServerConfigService);
        try {
            await service.getConfig();
        }
        catch (error) {
            // encryption key may have changed
            await service.setConfig({});
        }
    }
}
exports.ServerConfigProvider = ServerConfigProvider;
//# sourceMappingURL=server-config.provider.js.map