import { messages } from '../../core/messages/index.js';
const PADROES = {
    mode: 'compact',
    output: {
        format: 'console',
        jsonAscii: false,
        export: false,
        exportFull: false,
        exportDir: 'reports'
    },
    filters: {
        include: [],
        exclude: [],
        includeTests: false,
        includeNodeModules: false
    },
    performance: {
        fastMode: false
    },
    autoFix: {
        enabled: false,
        mode: 'balanced',
        dryRun: false
    },
    guardian: {
        enabled: false,
        fullScan: false,
        saveBaseline: false
    },
    verbosity: {
        level: 'info',
        silent: false
    },
    special: {
        listarAnalistas: false,
        criarArquetipo: false,
        salvarArquetipo: false,
        trustCompiler: false,
        verifyCycles: false
    },
};
export function validateAndNormalizeFlags(opts) {
    const errors = [];
    const warnings = [];
    const normalized = JSON.parse(JSON.stringify(PADROES));
    const modesAtivos = [opts.full && 'full', opts.executive && 'executive', opts.quick && 'quick'].filter((x) => typeof x === 'string');
    const optsExt = opts;
    if (optsExt.trustCompiler) {
        normalized.special = {
            ...normalized.special,
            trustCompiler: true
        };
    }
    if (optsExt.verifyCycles) {
        normalized.special = {
            ...normalized.special,
            verifyCycles: true
        };
    }
    if (modesAtivos.length > 1) {
        errors.push(messages.CliFlagsValidatorMensagens.conflitoModos(modesAtivos.join(', ')));
    }
    else if (modesAtivos.length === 1) {
        normalized.mode = modesAtivos[0];
    }
    const formatosAtivos = [opts.json && 'json', opts.markdown && 'markdown'].filter(Boolean);
    if (formatosAtivos.length > 1) {
        errors.push(messages.CliFlagsValidatorMensagens.conflitoFormatos(formatosAtivos.join(', ')));
    }
    else if (formatosAtivos.length === 1) {
        normalized.output.format = formatosAtivos[0];
    }
    if (opts.jsonAscii) {
        normalized.output.jsonAscii = true;
    }
    if (opts.export) {
        normalized.output.export = true;
    }
    if (opts.exportFull) {
        normalized.output.exportFull = true;
        normalized.output.export = true;
    }
    if (opts.exportTo) {
        normalized.output.exportDir = opts.exportTo;
    }
    if (opts.include && opts.include.length > 0) {
        normalized.filters.include = opts.include;
    }
    if (opts.exclude && opts.exclude.length > 0) {
        normalized.filters.exclude = opts.exclude;
    }
    if (optsExt.excludeTests) {
        normalized.filters.exclude = [...normalized.filters.exclude, '**/*.test.*', '**/*.spec.*', 'tests/**', 'test/**', '**/__tests__/**'];
    }
    if (opts.withTests) {
        normalized.filters.includeTests = true;
    }
    if (opts.withNodeModules) {
        normalized.filters.includeNodeModules = true;
    }
    if (opts.onlySrc && normalized.filters.include.length > 0) {
        warnings.push(messages.CliFlagsValidatorMensagens.onlySrcIgnorado);
    }
    else if (opts.onlySrc) {
        normalized.filters.include = ['src/**'];
    }
    if (opts.fix || opts.autoFix) {
        normalized.autoFix.enabled = true;
    }
    let modoAutoCorrecao;
    if (opts.autoCorrecaoMode) {
        modoAutoCorrecao = opts.autoCorrecaoMode;
    }
    else if (opts.fixMode) {
        modoAutoCorrecao = opts.fixMode;
    }
    else if (opts.autoFixConservative || opts.fixSafe) {
        modoAutoCorrecao = 'conservative';
    }
    else if (opts.fixAggressive) {
        modoAutoCorrecao = 'aggressive';
    }
    if (modoAutoCorrecao) {
        const validModes = ['conservative', 'balanced', 'aggressive'];
        if (validModes.includes(modoAutoCorrecao)) {
            normalized.autoFix.mode = modoAutoCorrecao;
        }
        else {
            warnings.push(messages.CliFlagsValidatorMensagens.modoAutoFixInvalido(modoAutoCorrecao));
        }
    }
    if (opts.dryRun) {
        normalized.autoFix.dryRun = true;
    }
    if (opts.guardian || opts.guardianCheck) {
        normalized.guardian.enabled = true;
    }
    if (opts.guardianFull) {
        normalized.guardian.fullScan = true;
        normalized.guardian.enabled = true;
    }
    if (opts.guardianBaseline) {
        normalized.guardian.saveBaseline = true;
        normalized.guardian.enabled = true;
    }
    if (optsExt.fast) {
        if (normalized.performance)
            normalized.performance.fastMode = true;
    }
    const verbosidadeAtiva = [opts.silent && 'silent', opts.quiet && 'quiet', opts.verbose && 'verbose'].filter(Boolean);
    if (verbosidadeAtiva.length > 1) {
        warnings.push(messages.CliFlagsValidatorMensagens.conflitoVerbose(verbosidadeAtiva.join(', ')));
    }
    if (opts.silent) {
        normalized.verbosity.silent = true;
        normalized.verbosity.level = 'error';
    }
    else if (opts.quiet) {
        normalized.verbosity.level = 'warn';
    }
    else if (opts.verbose || opts.debug) {
        normalized.verbosity.level = 'debug';
    }
    else if (opts.logNivel) {
        const validNiveis = ['error', 'warn', 'info', 'debug'];
        const level = opts.logNivel;
        if (validNiveis.includes(level)) {
            normalized.verbosity.level = level;
        }
        else {
            warnings.push(messages.CliFlagsValidatorMensagens.nivelLogInvalido(opts.logNivel));
        }
    }
    if (opts.listarAnalistas) {
        normalized.special.listarAnalistas = true;
    }
    if (opts.criarArquetipo) {
        normalized.special.criarArquetipo = true;
    }
    if (opts.salvarArquetipo) {
        normalized.special.salvarArquetipo = true;
        normalized.special.criarArquetipo = true;
        warnings.push(messages.CliFlagsValidatorMensagens.salvarArquetipoImplicaCriar);
    }
    return {
        valid: errors.length === 0,
        errors,
        warnings,
        normalized
    };
}
export function gerarSugestoes(flags) {
    const sugestoes = [];
    if (flags.mode === 'compact') {
        sugestoes.push(messages.CliFlagsValidatorMensagens.sugestaoFull);
    }
    else if (flags.mode === 'executive') {
        sugestoes.push(messages.CliFlagsValidatorMensagens.sugestaoExecutive);
    }
    if (!flags.output.export && flags.output.format === 'json') {
        sugestoes.push(messages.CliFlagsValidatorMensagens.sugestaoJsonExport);
    }
    if (flags.autoFix.enabled && !flags.autoFix.dryRun) {
        sugestoes.push(messages.CliFlagsValidatorMensagens.sugestaoAutoFixDryRun);
    }
    if (!flags.guardian.enabled) {
        sugestoes.push(messages.CliFlagsValidatorMensagens.sugestaoGuardian);
    }
    if (flags.filters.include.length === 0) {
        sugestoes.push(messages.CliFlagsValidatorMensagens.sugestaoInclude);
    }
    return sugestoes;
}
//# sourceMappingURL=flags-validator.js.map