"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 __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var InfoCommand_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InfoCommand = void 0;
const common_1 = require("@nestjs/common");
const nest_commander_1 = require("nest-commander");
const module_helper_1 = require("../helpers/module.helper");
const solid_registry_1 = require("../helpers/solid-registry");
const setting_service_1 = require("../services/setting.service");
const info_service_1 = require("../services/info.service");
let InfoCommand = InfoCommand_1 = class InfoCommand extends nest_commander_1.CommandRunner {
    constructor(solidRegistry, settingService, infoService) {
        super();
        this.solidRegistry = solidRegistry;
        this.settingService = settingService;
        this.infoService = infoService;
        this.logger = new common_1.Logger(InfoCommand_1.name);
    }
    async run(passedParam, options) {
        const enabledModules = (0, module_helper_1.getDynamicModuleNames)();
        const dataSources = this.getDataSources();
        const output = {
            packages: this.infoService.getPackageVersions(),
            modules: {
                count: enabledModules.length,
                names: enabledModules,
            },
            dataSources: {
                count: dataSources.length,
                items: dataSources,
            },
        };
        if (options?.detailed) {
            output.registry = this.getRegistryDetails();
        }
        console.log(JSON.stringify(output, null, 2));
    }
    getRegistryDetails() {
        const info = {
            settings: this.settingService.getAllSettings(),
            seeders: this.getWrapperNames(this.solidRegistry.getSeeders()),
            scheduledJobProviders: this.getWrapperNames(this.solidRegistry.getScheduledJobProviders()),
            selectionProviders: this.getWrapperNames(this.solidRegistry.getSelectionProviders()),
            computedFieldProviders: this.getWrapperNames(this.solidRegistry.getComputedFieldProviders()),
            solidDatabaseModules: this.getWrapperNames(this.solidRegistry.getSolidDatabaseModules()),
            dashboardVariableSelectionProviders: this.getWrapperNames(this.solidRegistry.getDashboardVariableSelectionProviders()),
            dashboardQuestionDataProviders: this.getWrapperNames(this.solidRegistry.getDashboardQuestionDataProviders()),
            mailProviders: this.getWrapperNames(this.solidRegistry.getMailProviders()),
            whatsappProviders: this.getWrapperNames(this.solidRegistry.getWhatsappProviders()),
            smsProviders: this.getWrapperNames(this.solidRegistry.getSmsProviders()),
            securityRuleConfigProviders: this.getWrapperNames(this.solidRegistry.getSecurityRuleConfigProviders()),
            errorCodeProviders: this.getWrapperNames(this.solidRegistry.getErrorCodeProviders()),
            controllers: this.solidRegistry.getControllers().map((controller) => controller.name),
        };
        return info;
    }
    getWrapperNames(wrappers) {
        return wrappers
            .map((wrapper) => wrapper.name || wrapper.instance?.constructor?.name)
            .filter((name) => !!name);
    }
    getDataSources() {
        const fromRegistry = this.solidRegistry
            .getSolidDatabaseModules()
            .map((wrapper) => wrapper.instance)
            .filter((module) => !!module)
            .map((module) => ({
            name: module.name?.(),
            type: module.type?.() ?? null,
        }))
            .filter((item) => !!item.name);
        return fromRegistry;
    }
    parseDetailed() {
        return true;
    }
};
exports.InfoCommand = InfoCommand;
__decorate([
    (0, nest_commander_1.Option)({ flags: '-d, --detailed', description: 'Print more details about the consuming project' }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Boolean)
], InfoCommand.prototype, "parseDetailed", null);
exports.InfoCommand = InfoCommand = InfoCommand_1 = __decorate([
    (0, nest_commander_1.Command)({ name: 'info', description: 'Prints information about the consuming project' }),
    __metadata("design:paramtypes", [solid_registry_1.SolidRegistry,
        setting_service_1.SettingService,
        info_service_1.InfoService])
], InfoCommand);
//# sourceMappingURL=info.command.js.map