"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var SolidRegistry_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SolidRegistry = exports.RESERVED_SOLID_KEYWORDS = void 0;
const common_1 = require("@nestjs/common");
var RESERVED_SOLID_KEYWORDS;
(function (RESERVED_SOLID_KEYWORDS) {
    RESERVED_SOLID_KEYWORDS["moduleMetadata"] = "moduleMetadata";
    RESERVED_SOLID_KEYWORDS["modelMetadata"] = "modelMetadata";
    RESERVED_SOLID_KEYWORDS["fieldMetadata"] = "fieldMetadata";
    RESERVED_SOLID_KEYWORDS["dataSource"] = "dataSource";
    RESERVED_SOLID_KEYWORDS["repository"] = "repository";
    RESERVED_SOLID_KEYWORDS["entityManager"] = "entityManager";
    RESERVED_SOLID_KEYWORDS["actionMetadata"] = "actionMetadata";
    RESERVED_SOLID_KEYWORDS["emailAttachment"] = "emailAttachment";
    RESERVED_SOLID_KEYWORDS["emailTemplate"] = "emailTemplate";
    RESERVED_SOLID_KEYWORDS["listOfValues"] = "listOfValues";
    RESERVED_SOLID_KEYWORDS["mediaStorageProvider"] = "mediaStorageProvider";
    RESERVED_SOLID_KEYWORDS["media"] = "media";
    RESERVED_SOLID_KEYWORDS["menuItemMetadata"] = "menuItemMetadata";
    RESERVED_SOLID_KEYWORDS["mqMessageQueue"] = "mqMessageQueue";
    RESERVED_SOLID_KEYWORDS["mqMessage"] = "mqMessage";
    RESERVED_SOLID_KEYWORDS["permissionMetadata"] = "permissionMetadata";
    RESERVED_SOLID_KEYWORDS["roleMetadata"] = "roleMetadata";
    RESERVED_SOLID_KEYWORDS["securityRule"] = "securityRule";
    RESERVED_SOLID_KEYWORDS["setting"] = "setting";
    RESERVED_SOLID_KEYWORDS["smsTemplate"] = "smsTemplate";
    RESERVED_SOLID_KEYWORDS["userMetadata"] = "userMetadata";
    RESERVED_SOLID_KEYWORDS["user"] = "user";
    RESERVED_SOLID_KEYWORDS["locale"] = "locale";
})(RESERVED_SOLID_KEYWORDS || (exports.RESERVED_SOLID_KEYWORDS = RESERVED_SOLID_KEYWORDS = {}));
let SolidRegistry = SolidRegistry_1 = class SolidRegistry {
    constructor() {
        this.logger = new common_1.Logger(SolidRegistry_1.name);
        this.extensionUserCreationProvider = null;
        this.seeders = new Set();
        this.scheduledJobProviders = new Set();
        this.selectionProviders = new Set();
        this.computedFieldProviders = new Set();
        this.solidDatabaseModules = new Set();
        this.controllers = new Set();
        this.modules = new Set();
        this.securityRules = [];
        this.locales = [];
        this.computedFieldMetadata = [];
        this.dashboardVariableSelectionProviders = new Set();
        this.dashboardQuestionDataProviders = new Set();
        this.mailProviders = new Set();
        this.whatsappProviders = new Set();
        this.smsProviders = new Set();
        this.securityRuleConfigProviders = new Set();
        this.errorCodeProviders = new Set();
        this.settingsProviders = new Set();
        this.auditableModels = new Set();
    }
    registerExtensionUserCreationProvider(provider) {
        if (this.extensionUserCreationProvider) {
            this.logger.warn(`ExtensionUserCreationProvider already registered by ${this.extensionUserCreationProvider.name}; ignoring ${provider.name}`);
            return;
        }
        this.extensionUserCreationProvider = provider;
    }
    getExtensionUserCreationProvider() {
        return this.extensionUserCreationProvider?.instance ?? null;
    }
    registerErrorCodeProvider(errorCodeProvider) {
        this.errorCodeProviders.add(errorCodeProvider);
    }
    registerWhatsappProvider(whatsappProvider) {
        this.whatsappProviders.add(whatsappProvider);
    }
    registerSmsProvider(smsProvider) {
        this.smsProviders.add(smsProvider);
    }
    registerSecurityRuleConfigProvider(securityRuleConfigProvider) {
        this.securityRuleConfigProviders.add(securityRuleConfigProvider);
    }
    registerMailProvider(mailProvider) {
        this.mailProviders.add(mailProvider);
    }
    registerController(name, methodNames) {
        this.controllers.add({ name: name, methods: methodNames });
    }
    registerControllers(controllers) {
        this.controllers = controllers;
    }
    registerSeeder(seeder) {
        this.seeders.add(seeder);
    }
    registerSelectionProvider(selectionProvider) {
        this.selectionProviders.add(selectionProvider);
    }
    registerDashboardVariableSelectionProvider(dashboardSelectionProvider) {
        this.dashboardVariableSelectionProviders.add(dashboardSelectionProvider);
    }
    registerDashboardQuestionDataProvider(dashboardQuestionDataProvider) {
        this.dashboardQuestionDataProviders.add(dashboardQuestionDataProvider);
    }
    registerComputedFieldProvider(computedFieldProvider) {
        this.computedFieldProviders.add(computedFieldProvider);
    }
    registerScheduledJobProvider(scheduledJobProvider) {
        this.scheduledJobProviders.add(scheduledJobProvider);
    }
    registerSolidDatabaseModule(solidDatabaseModule) {
        this.solidDatabaseModules.add(solidDatabaseModule);
    }
    registerModules(modules) {
        this.modules = new Set(modules);
    }
    registerSettingsProvider(provider) {
        this.settingsProviders.add(provider);
    }
    registerSecurityRules(securityRules) {
        this.securityRules = securityRules;
    }
    registerlocales(locales) {
        this.locales = locales;
    }
    registerComputedFieldMetadata(computedFieldMetadata) {
        this.computedFieldMetadata = computedFieldMetadata;
    }
    getSettingsProviders() {
        return Array.from(this.settingsProviders);
    }
    getSettingsProviderInstance(name) {
        const settingsProviders = this.getSettingsProviders();
        for (let i = 0; i < settingsProviders.length; i++) {
            const settingsProvider = settingsProviders[i];
            if (settingsProvider.instance.name() === name) {
                return settingsProvider.instance;
            }
        }
    }
    getMailProviders() {
        return Array.from(this.mailProviders);
    }
    getWhatsappProviders() {
        return Array.from(this.whatsappProviders);
    }
    getSmsProviders() {
        return Array.from(this.smsProviders);
    }
    getSecurityRuleConfigProviders() {
        return Array.from(this.securityRuleConfigProviders);
    }
    getSecurityRuleConfigProviderInstance(name) {
        const securityRuleConfigProviders = this.getSecurityRuleConfigProviders();
        for (let i = 0; i < securityRuleConfigProviders.length; i++) {
            const securityRuleConfigProvider = securityRuleConfigProviders[i];
            if (securityRuleConfigProvider.name === name) {
                return securityRuleConfigProvider.instance;
            }
        }
    }
    getSeeders() {
        return Array.from(this.seeders);
    }
    getControllers() {
        return Array.from(this.controllers);
    }
    getSelectionProviders() {
        return Array.from(this.selectionProviders);
    }
    getSelectionProviderInstance(name) {
        const selectionProviders = this.getSelectionProviders();
        for (let i = 0; i < selectionProviders.length; i++) {
            const selectionProvider = selectionProviders[i];
            if (selectionProvider.instance.name() === name) {
                return selectionProvider.instance;
            }
        }
    }
    getDashboardVariableSelectionProviders() {
        return Array.from(this.dashboardVariableSelectionProviders);
    }
    getDashboardVariableSelectionProviderInstance(name) {
        const dashboardSelectionProviders = this.getDashboardVariableSelectionProviders();
        for (let i = 0; i < dashboardSelectionProviders.length; i++) {
            const dashboardSelectionProvider = dashboardSelectionProviders[i];
            if (dashboardSelectionProvider.instance.name() === name) {
                return dashboardSelectionProvider.instance;
            }
        }
    }
    getErrorCodeProviders() {
        return Array.from(this.errorCodeProviders);
    }
    getErrorCodeProviderInstance(name) {
        const providers = this.getErrorCodeProviders();
        for (let i = 0; i < providers.length; i++) {
            const p = providers[i];
            if (p.instance?.name?.() === name)
                return p.instance;
        }
        return undefined;
    }
    getDashboardQuestionDataProviders() {
        return Array.from(this.dashboardQuestionDataProviders);
    }
    getDashboardQuestionDataProviderInstance(name) {
        const dashboardQuestionDataProviders = this.getDashboardQuestionDataProviders();
        for (let i = 0; i < dashboardQuestionDataProviders.length; i++) {
            const dasbhoardQuestionDataProvider = dashboardQuestionDataProviders[i];
            if (dasbhoardQuestionDataProvider.instance.name() === name) {
                return dasbhoardQuestionDataProvider.instance;
            }
        }
    }
    getComputedFieldProviders() {
        return Array.from(this.computedFieldProviders);
    }
    getScheduledJobProviders() {
        return Array.from(this.scheduledJobProviders);
    }
    getScheduledJobProviderInstance(name) {
        const scheduledJobProviders = this.getScheduledJobProviders();
        for (let i = 0; i < scheduledJobProviders.length; i++) {
            const scheduledJobProvider = scheduledJobProviders[i];
            if (scheduledJobProvider.name === name) {
                return scheduledJobProvider.instance;
            }
        }
    }
    getComputedFieldProvider(name) {
        const provider = this.getComputedFieldProviders().filter((provider) => provider.name === name).pop();
        if (!provider) {
            throw new Error(`Computed Field Provider with name ${name} not found`);
        }
        return provider;
    }
    getSolidDatabaseModules() {
        return Array.from(this.solidDatabaseModules);
    }
    getDefaultSolidDatabaseModule() {
        const solidDatabaseModulesAsArray = Array.from(this.solidDatabaseModules);
        for (let i = 0; i < solidDatabaseModulesAsArray.length; i++) {
            const solidDatabaseModule = solidDatabaseModulesAsArray[i];
            const solidDatabaseModuleInstance = solidDatabaseModule.instance;
            if (solidDatabaseModuleInstance.name() === 'default') {
                return solidDatabaseModuleInstance;
            }
        }
    }
    getModules() {
        return Array.from(this.modules);
    }
    getModule(name) {
        const module = this.getModules().filter((module) => module.name === name).pop();
        return module;
    }
    getComputedFieldMetadata() {
        return this.computedFieldMetadata;
    }
    getDefaultLocale() {
        return this.locales.find(locale => locale.isDefault === true) || null;
    }
    getSecurityRules(modelSingularName, roleNames = []) {
        if (roleNames.length === 0) {
            return this.securityRules.filter((rule) => rule.modelMetadata.singularName === modelSingularName);
        }
        return this.securityRules.filter((rule) => {
            return rule.modelMetadata.singularName === modelSingularName && roleNames.includes(rule.role.name);
        });
    }
    registerAuditableModels(models) {
        this.auditableModels = models;
    }
    isAuditableModel(modelSingularName) {
        return this.auditableModels.has(modelSingularName.toLowerCase());
    }
    getCommonEntityKeys() {
        return ['id', 'createdAt', 'updatedAt', 'deletedAt', 'createdBy', 'updatedBy', 'deletedTracker', 'localeName', 'defaultEntityLocaleId', 'publishedAt'];
    }
    getAllSettingsProviderInstance() {
        const settingsProviders = this.getSettingsProviders();
        for (let i = 0; i < settingsProviders.length; i++) {
            const settingsProvider = settingsProviders[i];
            return settingsProvider.instance;
        }
    }
};
exports.SolidRegistry = SolidRegistry;
exports.SolidRegistry = SolidRegistry = SolidRegistry_1 = __decorate([
    (0, common_1.Injectable)()
], SolidRegistry);
//# sourceMappingURL=solid-registry.js.map