"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentGenericTemplateProvider = void 0;
const __1 = require("../..");
const extension_provider_1 = require("../../integration/extension.provider");
const utils_common_provider_1 = require("../utils-common/utils-common.provider");
const content_generic_template_const_1 = require("./content-generic-template.const");
const content_generic_template_definition_1 = require("./content-generic-template.definition");
const transient_content_generic_service_1 = require("./transient-content-generic.service");
class ContentGenericTemplateProvider extends extension_provider_1.ExtensionProvider {
    constructor(app) {
        super(content_generic_template_const_1.CONTENT_GENERIC_PROVIDER, app);
        this.app = app;
        this.requiredProviders.push(utils_common_provider_1.UtilsCommonProvider);
        this.models.push(content_generic_template_definition_1.GenericTemplate);
        this.models.push(content_generic_template_definition_1.ContentGenericTemplate);
        this.repositories.push({ repoClass: content_generic_template_definition_1.ContentGenericTemplateRepository });
        this.services.push({ cls: content_generic_template_definition_1.ContentGenericTemplateService }, { cls: transient_content_generic_service_1.TransientContentGenericService });
        this.objectTypes.push(content_generic_template_const_1.TEMPLATE_CONFIGURATION_HOLDER_TYPE, content_generic_template_const_1.TEMPLATE_VIEW_TYPE, content_generic_template_const_1.TEMPLATE_CONFIGURATION_TYPE, content_generic_template_const_1.TEMPLATE_EMBEDDED_CONFIGURATION_TYPE, content_generic_template_const_1.TEMPLATE_REFERRER_TYPE);
        this.objectSubTypes.push(content_generic_template_const_1.TEMPLATE_CONFIGURATION_HOLDER_TEMPLATE_CONFIGURATION_SUBTYPE, content_generic_template_const_1.TEMPLATE_VIEW_TEMPLATE_EMBEDDED_CONFIGURATION_SUBTYPE);
    }
    async boot() {
        for (const typeField of this.appCtx.implementingTypes.value[content_generic_template_const_1.TEMPLATE_VIEW_TYPE.name]) {
            const allTypes = await this.objectTypeService.searchAll();
            await this.addType({
                name: allTypes[typeField].name + 'Configuration',
                inheritedTypesIds: [content_generic_template_const_1.TEMPLATE_CONFIGURATION_TYPE.name],
                definition: {
                    properties: {
                        templateObjectTreeId: {
                            oneOfTree: [
                                {
                                    treeType: allTypes[typeField].name,
                                },
                                {
                                    treeType: allTypes[typeField].name,
                                    namespaceName: __1.TEMPLATES_OBJECT_NAME,
                                    namespaceType: __1.ObjectTypeName.REPOSITORY_CATEGORY,
                                    ownerName: __1.PUBLIC_OBJECT_NAME,
                                    ownerType: __1.ObjectTypeName.REPOSITORY,
                                },
                            ],
                        },
                    },
                },
            });
            await this.addType({
                name: allTypes[typeField].name + 'EmbeddedConfiguration',
                inheritedTypesIds: [
                    allTypes[typeField].name + 'Configuration',
                    content_generic_template_const_1.TEMPLATE_EMBEDDED_CONFIGURATION_TYPE.name,
                ],
            });
            await this.addSubType({
                typeName: allTypes[typeField].name,
                subTypeName: allTypes[typeField].name + 'EmbeddedConfiguration',
                name: content_generic_template_const_1.TEMPLATE_CONFIGURATION_TYPE.name,
                tree: true,
            });
        }
        await super.boot();
    }
}
exports.ContentGenericTemplateProvider = ContentGenericTemplateProvider;
//# sourceMappingURL=content-generic-template.provider.js.map