"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TemplateGenerator = void 0;
const types_1 = require("../types");
const file_manager_1 = require("./file-manager");
const fs = require("node:fs");
const path = require("node:path");
class TemplateGenerator {
    // generate static files from templates folder,
    // with templateElement know that type of element create, bounded_context, module, etc.
    // makes a wrapper of generateContents to centralize the content generation calls
    // from the template generator
    static generateStaticContents(command, templateElement, relativeTargetBasePath, relativeTargetPath, { boundedContextName = '', moduleName = '', moduleNames = '', additionalApi, force = false, verbose = false, excludeFiles = [], lockFiles = [], templateData = {}, currentProperty, // property to render value object or pivot table
    useTemplateEngine = true, templateElementPath, } = {}) {
        file_manager_1.FileManager.generateContents(command, path.join(TemplateGenerator.templatePath, ...templateElement.split('/'), templateElementPath || ''), relativeTargetBasePath, relativeTargetPath, {
            boundedContextName,
            moduleName,
            moduleNames,
            additionalApi,
            force,
            verbose,
            excludeFiles,
            lockFiles,
            templateData,
            currentProperty,
            useTemplateEngine,
        });
    }
    static createDirectory(relativeTargetBasePath, directory) {
        const modulePath = path.join(TemplateGenerator.projectDirectory, relativeTargetBasePath, directory);
        if (!fs.existsSync(modulePath))
            fs.mkdirSync(modulePath, { recursive: true });
    }
    /**
     * @param {GenerateCommandState} generateCommandState Generate command state
     * @param {string} relativeTargetBasePath Relative target base path
     * @param {string} relativeTargetPath Relative target path
     * @param {Property[]} valueObjects Value objects
     * @param {string} moduleName Module name
     * @returns void
     */
    static generateValueObjects(generateCommandState, relativeTargetBasePath, relativeTargetPath, valueObjects, moduleName) {
        // iterate properties to generate ValueObjects
        for (const property of valueObjects) {
            TemplateGenerator.generateValueObject(generateCommandState, relativeTargetBasePath, relativeTargetPath, property, moduleName);
        }
    }
    /**
     * @param {GenerateCommandState} generateCommandState Generate command state
     * @param {string} relativeTargetBasePath Relative target base path
     * @param {string} relativeTargetPath Relative target path
     * @param {Property} property Property
     * @param {string} moduleName Module name
     * @return void
     */
    static generateValueObject(generateCommandState, relativeTargetBasePath, relativeTargetPath, property, moduleName) {
        // read value object from our data type
        const originFilePath = path.join(TemplateGenerator.templatePath, ...types_1.TemplateElement.BACK_VALUE_OBJECT.split('/'), property.type, '__module_name__-__property_name__.ts');
        // TODO, throw error when no exist value object
        // check that exists value object template
        if (!fs.existsSync(originFilePath))
            return;
        file_manager_1.FileManager.manageFileTemplate(generateCommandState.command, originFilePath, '__module_name__-__property_name__.ts', path.join(relativeTargetBasePath, relativeTargetPath, moduleName, 'domain', 'value-objects'), {
            force: generateCommandState.flags.force,
            verbose: generateCommandState.flags.verbose,
            templateData: { ...generateCommandState },
            moduleNameSuffix: property.isI18n ? 'i18n' : '',
            currentProperty: property,
            boundedContextName: generateCommandState.schema.boundedContextName,
            moduleName: generateCommandState.schema.moduleName,
            moduleNames: generateCommandState.schema.moduleNames,
            lockFiles: generateCommandState.lockFiles,
        });
    }
}
exports.TemplateGenerator = TemplateGenerator;
TemplateGenerator.templatePath = path.join(__dirname, '..', '..', 'templates');
TemplateGenerator.projectDirectory = process.cwd();
