import { snakeCase, upperCase } from 'lodash-es';
import springBootCommand from '../../generators/spring-boot/command.js';
import liquibaseCommand from '../../generators/liquibase/command.js';
import gatewayCommand from '../../generators/spring-cloud/generators/gateway/command.js';
import { extractJdlDefinitionFromCommandConfig } from './converter.js';
export const buildJDLApplicationConfig = (configs) => {
    const jdlOptions = extractJdlDefinitionFromCommandConfig(configs);
    return {
        quotedOptionNames: [],
        tokenConfigs: jdlOptions.map(option => ({
            name: upperCase(snakeCase(option.name)),
            pattern: option.name,
        })),
        validatorConfig: Object.fromEntries(jdlOptions.map(option => [
            upperCase(snakeCase(option.name)),
            {
                type: option.tokenType,
                pattern: option.tokenValuePattern,
                msg: `${option.name} property`,
            },
        ])),
        optionsValues: Object.fromEntries(jdlOptions
            .filter(option => option.knownChoices)
            .map(option => [option.name, Object.fromEntries(option.knownChoices.map(choice => [choice, choice]))])),
        optionsTypes: Object.fromEntries(jdlOptions.map(option => [
            option.name,
            {
                type: option.type,
            },
        ])),
    };
};
let defaultJDLApplicationConfig;
export const getDefaultJDLApplicationConfig = () => {
    if (defaultJDLApplicationConfig === undefined) {
        defaultJDLApplicationConfig = buildJDLApplicationConfig({
            ...springBootCommand.configs,
            ...liquibaseCommand.configs,
            ...gatewayCommand.configs,
        });
    }
    return defaultJDLApplicationConfig;
};
