"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateYamlConfigFile = void 0;
const path = require("node:path");
const fs = require("node:fs");
const yaml = require("js-yaml");
const _ = require("lodash");
const config_1 = require("../../config");
const generateYamlConfigFile = async (generateCommandState) => {
    // write yaml file
    const yamlStr = yaml.dump({
        version: config_1.cliterConfig.configYamlVersion,
        boundedContextName: generateCommandState.schema.boundedContextName,
        moduleName: generateCommandState.schema.moduleName,
        moduleNames: generateCommandState.schema.moduleNames,
        aggregateName: generateCommandState.schema.aggregateName,
        hasOAuth: generateCommandState.schema.hasOAuth,
        hasTenant: generateCommandState.schema.hasTenant,
        hasAuditing: generateCommandState.schema.hasAuditing,
        aggregateProperties: generateCommandState.schema.properties.toDto().map(item => _.omit(item, ['id'])),
        additionalApis: generateCommandState.schema.additionalApis.toDto().map(item => _.omit(item, ['pathSegments', 'pathBoundedContext', 'pathAction'])),
        excluded: generateCommandState.schema.excluded,
    }, {
        lineWidth: -1,
        skipInvalid: true,
    });
    const yamlPath = path.join(process.cwd(), 'cliter', generateCommandState.schema.boundedContextName.toKebabCase());
    if (!fs.existsSync(yamlPath))
        fs.mkdirSync(yamlPath, { recursive: true });
    fs.writeFileSync(path.join(yamlPath, `${generateCommandState.schema.moduleName}${config_1.cliterConfig.schemaDefinitionExtension}`), yamlStr, 'utf8');
};
exports.generateYamlConfigFile = generateYamlConfigFile;
