"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("node:path");
const fs = require("node:fs");
const chalk = require("chalk");
const inquirer = require("inquirer");
const emoji = require("node-emoji");
const logSymbols = require("log-symbols");
const core_1 = require("@oclif/core");
const _cliter_1 = require("../../@cliter");
class Delete extends core_1.Command {
    async run() {
        const { args, flags } = await this.parse(Delete);
        if (args.firstArg === 'b')
            args.firstArg = _cliter_1.TemplateElement.BACK_BOUNDED_CONTEXT;
        if (args.firstArg === 'm')
            args.firstArg = _cliter_1.TemplateElement.BACK_APP;
        if (args.firstArg === _cliter_1.TemplateElement.BACK_APP) {
            if (fs.existsSync(path.join(process.cwd(), 'src', _cliter_1.cliterConfig.appContainer, args.secondArg))) {
                if ((await this.promptForDelete(args.secondArg)).hasDelete) {
                    _cliter_1.FsExtend.rmDir(path.join(process.cwd(), 'src', _cliter_1.cliterConfig.appContainer, args.secondArg));
                    this.log(`%s %s Module ${args.secondArg} has been deleted %s`, chalk.green.bold('DONE'), emoji.get('open_file_folder'), logSymbols.success);
                }
            }
            else {
                this.log(`%s Module ${args.secondArg} not exist, be sure to enter the module in the format: bounded-context/module %s`, chalk.yellow.bold('WARNING'), logSymbols.warning);
            }
        }
    }
    async promptForDelete(elementName) {
        const questions = [];
        questions.push({
            name: 'hasDelete',
            message: `Do you want delete the module ${elementName}?`,
            type: 'confirm',
        });
        return await inquirer.prompt(questions);
    }
}
exports.default = Delete;
Delete.description = 'Delete elements';
Delete.flags = {
    help: core_1.Flags.help({ char: 'h' }),
};
Delete.args = {
    firstArg: core_1.Args.string({
        name: 'elementType',
        description: 'Type element to delete',
        options: ['bounded-context', 'b', 'module', 'm'],
        required: true,
    }),
    secondArg: core_1.Args.string({
        name: 'elementName',
        description: 'Name element to create',
        required: true,
    }),
};
