import { promises as fs } from 'node:fs';
import path from 'node:path';
import { messages } from '../core/messages/index.js';
const log = messages.log;
const PADRAO_ALIAS_CONFIGURACAO = {
    "@": "./src/types/index.ts",
    "@analysts/architects": "./src/analysts/architects/index.ts",
    "@analysts/azure-pipelines": "./src/analysts/azure-pipelines/index.ts",
    "@analysts/azure-pipelines/analysts": "./src/analysts/azure-pipelines/analysts/index.ts",
    "@analysts/azure-pipelines/corrections": "./src/analysts/azure-pipelines/corrections/index.ts",
    "@analysts/azure-pipelines/detectors": "./src/analysts/azure-pipelines/detectors/index.ts",
    "@analysts/azure-pipelines/reports": "./src/analysts/azure-pipelines/reports/index.ts",
    "@analysts/azure-pipelines/scorers": "./src/analysts/azure-pipelines/scorers/index.ts",
    "@analysts/circleci": "./src/analysts/circleci/index.ts",
    "@analysts/circleci/analysts": "./src/analysts/circleci/analysts/index.ts",
    "@analysts/circleci/corrections": "./src/analysts/circleci/corrections/index.ts",
    "@analysts/circleci/detectors": "./src/analysts/circleci/detectors/index.ts",
    "@analysts/circleci/reports": "./src/analysts/circleci/reports/index.ts",
    "@analysts/circleci/scorers": "./src/analysts/circleci/scorers/index.ts",
    "@analysts/converters": "./src/analysts/converters/index.ts",
    "@analysts/converters/engines": "./src/analysts/converters/engines/index.ts",
    "@analysts/corrections": "./src/analysts/corrections/index.ts",
    "@analysts/corrections/quick-fixes": "./src/analysts/corrections/quick-fixes/index.ts",
    "@analysts/corrections/type-safety": "./src/analysts/corrections/type-safety/index.ts",
    "@analysts/css": "./src/analysts/css/index.ts",
    "@analysts/css-in-js": "./src/analysts/css-in-js/index.ts",
    "@analysts/css-in-js/analysts": "./src/analysts/css-in-js/analysts/index.ts",
    "@analysts/css-in-js/corrections": "./src/analysts/css-in-js/corrections/index.ts",
    "@analysts/css-in-js/detectors": "./src/analysts/css-in-js/detectors/index.ts",
    "@analysts/css-in-js/scorers": "./src/analysts/css-in-js/scorers/index.ts",
    "@analysts/css/analysts": "./src/analysts/css/analysts/index.ts",
    "@analysts/css/corrections": "./src/analysts/css/corrections/index.ts",
    "@analysts/css/detectors": "./src/analysts/css/detectors/index.ts",
    "@analysts/css/scorers": "./src/analysts/css/scorers/index.ts",
    "@analysts/detectors": "./src/analysts/detectors/index.ts",
    "@analysts/github-actions": "./src/analysts/github-actions/index.ts",
    "@analysts/github-actions/analysts": "./src/analysts/github-actions/analysts/index.ts",
    "@analysts/github-actions/corrections": "./src/analysts/github-actions/corrections/index.ts",
    "@analysts/github-actions/detectors": "./src/analysts/github-actions/detectors/index.ts",
    "@analysts/github-actions/reports": "./src/analysts/github-actions/reports/index.ts",
    "@analysts/github-actions/scorers": "./src/analysts/github-actions/scorers/index.ts",
    "@analysts/gitlab-ci": "./src/analysts/gitlab-ci/index.ts",
    "@analysts/gitlab-ci/analysts": "./src/analysts/gitlab-ci/analysts/index.ts",
    "@analysts/gitlab-ci/corrections": "./src/analysts/gitlab-ci/corrections/index.ts",
    "@analysts/gitlab-ci/detectors": "./src/analysts/gitlab-ci/detectors/index.ts",
    "@analysts/gitlab-ci/reports": "./src/analysts/gitlab-ci/reports/index.ts",
    "@analysts/gitlab-ci/scorers": "./src/analysts/gitlab-ci/scorers/index.ts",
    "@analysts/go": "./src/analysts/go/index.ts",
    "@analysts/go/analysts": "./src/analysts/go/analysts/index.ts",
    "@analysts/go/detectors": "./src/analysts/go/detectors/index.ts",
    "@analysts/html": "./src/analysts/html/index.ts",
    "@analysts/html/analysts": "./src/analysts/html/analysts/index.ts",
    "@analysts/html/corrections": "./src/analysts/html/corrections/index.ts",
    "@analysts/html/detectors": "./src/analysts/html/detectors/index.ts",
    "@analysts/html/scorers": "./src/analysts/html/scorers/index.ts",
    "@analysts/jenkins": "./src/analysts/jenkins/index.ts",
    "@analysts/jenkins/analysts": "./src/analysts/jenkins/analysts/index.ts",
    "@analysts/jenkins/corrections": "./src/analysts/jenkins/corrections/index.ts",
    "@analysts/jenkins/detectors": "./src/analysts/jenkins/detectors/index.ts",
    "@analysts/jenkins/reports": "./src/analysts/jenkins/reports/index.ts",
    "@analysts/jenkins/scorers": "./src/analysts/jenkins/scorers/index.ts",
    "@analysts/js-ts": "./src/analysts/js-ts/index.ts",
    "@analysts/js-ts/analysts": "./src/analysts/js-ts/analysts/index.ts",
    "@analysts/js-ts/detectors": "./src/analysts/js-ts/detectors/index.ts",
    "@analysts/php": "./src/analysts/php/index.ts",
    "@analysts/php/analysts": "./src/analysts/php/analysts/index.ts",
    "@analysts/plugins": "./src/analysts/plugins/index.ts",
    "@analysts/python": "./src/analysts/python/index.ts",
    "@analysts/python/analysts": "./src/analysts/python/analysts/index.ts",
    "@analysts/python/corrections": "./src/analysts/python/corrections/index.ts",
    "@analysts/python/detectors": "./src/analysts/python/detectors/index.ts",
    "@analysts/python/scorers": "./src/analysts/python/scorers/index.ts",
    "@analysts/react": "./src/analysts/react/index.ts",
    "@analysts/react/analysts": "./src/analysts/react/analysts/index.ts",
    "@analysts/react/corrections": "./src/analysts/react/corrections/index.ts",
    "@analysts/react/detectors": "./src/analysts/react/detectors/index.ts",
    "@analysts/react/scorers": "./src/analysts/react/scorers/index.ts",
    "@analysts/registry": "./src/analysts/registry/index.ts",
    "@analysts/rust": "./src/analysts/rust/index.ts",
    "@analysts/rust/analysts": "./src/analysts/rust/analysts/index.ts",
    "@analysts/rust/detectors": "./src/analysts/rust/detectors/index.ts",
    "@analysts/scorers": "./src/analysts/scorers/index.ts",
    "@analysts/shell": "./src/analysts/shell/index.ts",
    "@analysts/shell/analysts": "./src/analysts/shell/analysts/index.ts",
    "@analysts/shell/corrections": "./src/analysts/shell/corrections/index.ts",
    "@analysts/shell/detectors": "./src/analysts/shell/detectors/index.ts",
    "@analysts/shell/scorers": "./src/analysts/shell/scorers/index.ts",
    "@analysts/sql": "./src/analysts/sql/index.ts",
    "@analysts/sql/analysts": "./src/analysts/sql/analysts/index.ts",
    "@analysts/sql/corrections": "./src/analysts/sql/corrections/index.ts",
    "@analysts/sql/detectors": "./src/analysts/sql/detectors/index.ts",
    "@analysts/sql/scorers": "./src/analysts/sql/scorers/index.ts",
    "@analysts/strategists": "./src/analysts/strategists/index.ts",
    "@analysts/svg": "./src/analysts/svg/index.ts",
    "@analysts/svg/analysts": "./src/analysts/svg/analysts/index.ts",
    "@analysts/svg/corrections": "./src/analysts/svg/corrections/index.ts",
    "@analysts/svg/detectors": "./src/analysts/svg/detectors/index.ts",
    "@analysts/svg/scorers": "./src/analysts/svg/scorers/index.ts",
    "@analysts/tailwind": "./src/analysts/tailwind/index.ts",
    "@analysts/tailwind/analysts": "./src/analysts/tailwind/analysts/index.ts",
    "@analysts/tailwind/corrections": "./src/analysts/tailwind/corrections/index.ts",
    "@analysts/tailwind/detectors": "./src/analysts/tailwind/detectors/index.ts",
    "@analysts/tailwind/scorers": "./src/analysts/tailwind/scorers/index.ts",
    "@analysts/xml": "./src/analysts/xml/index.ts",
    "@analysts/xml/analysts": "./src/analysts/xml/analysts/index.ts",
    "@analysts/xml/corrections": "./src/analysts/xml/corrections/index.ts",
    "@analysts/xml/detectors": "./src/analysts/xml/detectors/index.ts",
    "@analysts/xml/scorers": "./src/analysts/xml/scorers/index.ts",
    "@api": "./src/api/index.ts",
    "@api/middleware": "./src/api/middleware/index.ts",
    "@api/routes": "./src/api/routes/index.ts",
    "@api/server": "./src/api/server.ts",
    "@api/services": "./src/api/services/index.ts",
    "@app": "./src/app/index.ts",
    "@app/changelog": "./src/app/changelog/index.ts",
    "@app/github": "./src/app/github/app/index.ts",
    "@app/github/app": "./src/app/github/app/index.ts",
    "@app/github/dashboard": "./src/app/github/dashboard/index.ts",
    "@app/github/jobs": "./src/app/github/jobs/index.ts",
    "@app/github/push-analysis": "./src/app/github/push-analysis/index.ts",
    "@app/privacy-policy": "./src/app/privacy-policy/index.ts",
    "@app/terms-of-use": "./src/app/terms-of-use/index.ts",
    "@caretakers": "./src/caretakers/index.ts",
    "@cli": "./src/cli/index.ts",
    "@cli/commands": "./src/cli/commands/index.ts",
    "@cli/diagnostic": "./src/cli/diagnostic/index.ts",
    "@cli/diagnostic/exporters": "./src/cli/diagnostic/exporters/index.ts",
    "@cli/diagnostic/handlers": "./src/cli/diagnostic/handlers/index.ts",
    "@cli/handlers": "./src/cli/handlers/index.ts",
    "@cli/helpers": "./src/cli/helpers/index.ts",
    "@cli/options": "./src/cli/options/index.ts",
    "@cli/processing": "./src/cli/processing/index.ts",
    "@core/config": "./src/core/config/index.ts",
    "@core/config/auto": "./src/core/config/auto/index.ts",
    "@core/execution": "./src/core/execution/index.ts",
    "@core/formatters": "./src/core/formatters/index.ts",
    "@core/messages": "./src/core/messages/index.ts",
    "@core/messages/en": "./src/core/messages/en/index.ts",
    "@core/messages/en/analysts": "./src/core/messages/en/analysts/index.ts",
    "@core/messages/en/api": "./src/core/messages/en/api/index.ts",
    "@core/messages/en/caretakers": "./src/core/messages/en/caretakers/index.ts",
    "@core/messages/en/cli": "./src/core/messages/en/cli/index.ts",
    "@core/messages/en/core": "./src/core/messages/en/core/index.ts",
    "@core/messages/en/github": "./src/core/messages/en/github/index.ts",
    "@core/messages/en/guardian": "./src/core/messages/en/guardian/index.ts",
    "@core/messages/en/licenses": "./src/core/messages/en/licenses/index.ts",
    "@core/messages/en/log": "./src/core/messages/en/log/index.ts",
    "@core/messages/en/reports": "./src/core/messages/en/reports/index.ts",
    "@core/messages/en/shared": "./src/core/messages/en/shared/index.ts",
    "@core/messages/en/ui": "./src/core/messages/en/ui/index.ts",
    "@core/messages/ja": "./src/core/messages/ja/index.ts",
    "@core/messages/ja/analysts": "./src/core/messages/ja/analysts/index.ts",
    "@core/messages/ja/api": "./src/core/messages/ja/api/index.ts",
    "@core/messages/ja/caretakers": "./src/core/messages/ja/caretakers/index.ts",
    "@core/messages/ja/cli": "./src/core/messages/ja/cli/index.ts",
    "@core/messages/ja/core": "./src/core/messages/ja/core/index.ts",
    "@core/messages/ja/github": "./src/core/messages/ja/github/index.ts",
    "@core/messages/ja/guardian": "./src/core/messages/ja/guardian/index.ts",
    "@core/messages/ja/licenses": "./src/core/messages/ja/licenses/index.ts",
    "@core/messages/ja/log": "./src/core/messages/ja/log/index.ts",
    "@core/messages/ja/reports": "./src/core/messages/ja/reports/index.ts",
    "@core/messages/ja/shared": "./src/core/messages/ja/shared/index.ts",
    "@core/messages/ja/ui": "./src/core/messages/ja/ui/index.ts",
    "@core/messages/pt": "./src/core/messages/pt/index.ts",
    "@core/messages/pt/analysts": "./src/core/messages/pt/analysts/index.ts",
    "@core/messages/pt/api": "./src/core/messages/pt/api/index.ts",
    "@core/messages/pt/caretakers": "./src/core/messages/pt/caretakers/index.ts",
    "@core/messages/pt/cli": "./src/core/messages/pt/cli/index.ts",
    "@core/messages/pt/core": "./src/core/messages/pt/core/index.ts",
    "@core/messages/pt/github": "./src/core/messages/pt/github/index.ts",
    "@core/messages/pt/guardian": "./src/core/messages/pt/guardian/index.ts",
    "@core/messages/pt/licenses": "./src/core/messages/pt/licenses/index.ts",
    "@core/messages/pt/log": "./src/core/messages/pt/log/index.ts",
    "@core/messages/pt/reports": "./src/core/messages/pt/reports/index.ts",
    "@core/messages/pt/shared": "./src/core/messages/pt/shared/index.ts",
    "@core/messages/pt/ui": "./src/core/messages/pt/ui/index.ts",
    "@core/messages/shared": "./src/core/messages/shared/index.ts",
    "@core/messages/zh": "./src/core/messages/zh/index.ts",
    "@core/messages/zh/analysts": "./src/core/messages/zh/analysts/index.ts",
    "@core/messages/zh/api": "./src/core/messages/zh/api/index.ts",
    "@core/messages/zh/caretakers": "./src/core/messages/zh/caretakers/index.ts",
    "@core/messages/zh/cli": "./src/core/messages/zh/cli/index.ts",
    "@core/messages/zh/core": "./src/core/messages/zh/core/index.ts",
    "@core/messages/zh/github": "./src/core/messages/zh/github/index.ts",
    "@core/messages/zh/guardian": "./src/core/messages/zh/guardian/index.ts",
    "@core/messages/zh/licenses": "./src/core/messages/zh/licenses/index.ts",
    "@core/messages/zh/log": "./src/core/messages/zh/log/index.ts",
    "@core/messages/zh/reports": "./src/core/messages/zh/reports/index.ts",
    "@core/messages/zh/shared": "./src/core/messages/zh/shared/index.ts",
    "@core/messages/zh/ui": "./src/core/messages/zh/ui/index.ts",
    "@core/parsing": "./src/core/parsing/index.ts",
    "@core/parsing/langs": "./src/core/parsing/langs/index.ts",
    "@core/registry": "./src/core/registry/index.ts",
    "@core/reporting": "./src/core/reporting/index.ts",
    "@core/runtime": "./src/core/runtime/index.ts",
    "@core/schema": "./src/core/schema/index.ts",
    "@core/utils": "./src/core/utils/index.ts",
    "@core/workers": "./src/core/workers/index.ts",
    "@guardian": "./src/guardian/index.ts",
    "@lib": "./src/lib/index.ts",
    "@licenses": "./src/licenses/index.ts",
    "@lsp": "./src/lsp/index.ts",
    "@reports": "./src/reports/index.ts",
    "@reports/compliance": "./src/reports/compliance/index.ts",
    "@sdk": "./src/sdk/index.ts",
    "@shared": "./src/shared/index.ts",
    "@shared/data-processing": "./src/shared/data-processing/index.ts",
    "@shared/formatters": "./src/shared/formatters/index.ts",
    "@shared/formatters/core": "./src/shared/formatters/core/index.ts",
    "@shared/formatters/engines": "./src/shared/formatters/engines/index.ts",
    "@shared/formatters/formatters": "./src/shared/formatters/formatters/index.ts",
    "@shared/helpers": "./src/shared/helpers/index.ts",
    "@shared/marketplace": "./src/shared/marketplace/index.ts",
    "@shared/persistence": "./src/shared/persistence/index.ts",
    "@shared/plugins": "./src/shared/plugins/index.ts",
    "@shared/validation": "./src/shared/validation/index.ts",
    "@types": "./src/types/index.ts",
    "@types/analysts": "./src/types/analysts/index.ts",
    "@types/analysts/corrections": "./src/types/analysts/corrections/index.ts",
    "@types/analysts/html": "./src/types/analysts/html.ts",
    "@types/caretakers": "./src/types/caretakers/index.ts",
    "@types/cli": "./src/types/cli/index.ts",
    "@types/common": "./src/types/common/index.ts",
    "@types/core": "./src/types/core/index.ts",
    "@types/core/config": "./src/types/core/config/index.ts",
    "@types/core/corrections": "./src/types/core/corrections/index.ts",
    "@types/core/execution": "./src/types/core/execution/index.ts",
    "@types/core/parsing": "./src/types/core/parsing/index.ts",
    "@types/core/utils": "./src/types/core/utils/index.ts",
    "@types/github": "./src/types/github/index.ts",
    "@types/guardian": "./src/types/guardian/index.ts",
    "@types/licenses": "./src/types/licenses/index.ts",
    "@types/project": "./src/types/project/index.ts",
    "@types/reports": "./src/types/reports/index.ts",
    "@types/scripts": "./src/types/scripts/index.ts",
    "@types/sdk": "./src/types/sdk/index.ts",
    "@types/shared": "./src/types/shared/index.ts",
    "@types/structure": "./src/types/structure/index.ts",
    "@types/types": "./src/types/index.ts",
    "@types/vulnerabilities": "./src/types/vulnerabilities/index.ts",
    "@vulnerabilities": "./src/vulnerabilities/index.ts"
};
const PADROES = {
    tiposComExtensao: /@types\/types\.js\b/g,
    importRelativo: /from\s+ (['"])(\.\ \/\\.+?)\1/g
};
async function* walkDirectory(dir) {
    try {
        const entries = await fs.readdir(dir, {
            withFileTypes: true
        });
        for (const entry of entries) {
            const fullCaminho = path.join(dir, entry.name);
            if (entry.isDirectory()) {
                if (['node_modules', 'dist', 'coverage', '.git'].includes(entry.name)) {
                    continue;
                }
                yield* walkDirectory(fullCaminho);
            }
            else if (entry.isFile()) {
                if (/\.(ts|tsx|js|jsx|mjs|cjs)$/.test(entry.name)) {
                    yield fullCaminho;
                }
            }
        }
    }
    catch (error) {
        log.erro(messages.ERROS_IMPORTS.lerDiretorio(dir, error));
    }
}
function corrigirImportsTipos(conteudo) {
    const correcoes = [];
    let conteudoAtualizado = conteudo;
    conteudoAtualizado = conteudoAtualizado.replace(PADROES.tiposComExtensao, (match, offset) => {
        correcoes.push({
            tipo: 'tipos-extensao',
            de: match,
            para: '@types/types',
            linha: conteudo.substring(0, offset).split('\n').length
        });
        return '@types/types';
    });
    const regex = / (['"])(@types\/[^'"]+)\1/g;
    conteudoAtualizado = conteudoAtualizado.replace(regex, (match, quote, subpath, offset) => {
        const normalized = String(subpath || '').trim();
        if (normalized === 'types')
            return match;
        if (normalized === 'types.js') {
            const novoImport = `${quote}@types/types${quote}`;
            correcoes.push({
                tipo: 'tipos-extensao',
                de: match,
                para: novoImport,
                linha: conteudo.substring(0, offset).split('\n').length
            });
            return novoImport;
        }
        const novoImport = `${quote}@types/types${quote}`;
        correcoes.push({
            tipo: 'tipos-subpath',
            de: match,
            para: novoImport,
            linha: conteudo.substring(0, offset).split('\n').length
        });
        return novoImport;
    });
    return {
        conteudo: conteudoAtualizado,
        correcoes
    };
}
function corrigirImportsRelativos(conteudo, _filePath, _projectRoot, _aliasConfig) {
    const correcoes = [];
    const conteudoAtualizado = conteudo;
    return {
        conteudo: conteudoAtualizado,
        correcoes
    };
}
async function processarArquivo(fileCaminho, options) {
    const resultado = {
        arquivo: path.relative(options.projectRaiz, fileCaminho),
        correcoes: [],
        modificado: false
    };
    try {
        const conteudoOriginal = await fs.readFile(fileCaminho, 'utf-8');
        let conteudoAtualizado = conteudoOriginal;
        if (options.corrigirTipos !== false) {
            const { conteudo, correcoes } = corrigirImportsTipos(conteudoAtualizado);
            conteudoAtualizado = conteudo;
            resultado.correcoes.push(...correcoes);
        }
        if (options.corrigirRelativos !== false) {
            const { conteudo, correcoes } = corrigirImportsRelativos(conteudoAtualizado, fileCaminho, options.projectRaiz, options.aliasConfig || PADRAO_ALIAS_CONFIGURACAO);
            conteudoAtualizado = conteudo;
            resultado.correcoes.push(...correcoes);
        }
        if (conteudoAtualizado !== conteudoOriginal) {
            if (!options.dryRun) {
                await fs.writeFile(fileCaminho, conteudoAtualizado, 'utf-8');
            }
            resultado.modificado = true;
        }
    }
    catch (error) {
        resultado.erro = error instanceof Error ? error.message : String(error);
    }
    return resultado;
}
export async function executarZeladorImports(targetDirs, options = {}) {
    const projectRaiz = options.projectRaiz || process.cwd();
    const fullOpcoes = {
        projectRaiz,
        dryRun: options.dryRun ?? false,
        verbose: options.verbose ?? false,
        corrigirTipos: options.corrigirTipos ?? true,
        corrigirRelativos: options.corrigirRelativos ?? false,
        aliasConfig: options.aliasConfig || PADRAO_ALIAS_CONFIGURACAO
    };
    const resultados = [];
    for (const dir of targetDirs) {
        const fullCaminho = path.resolve(projectRaiz, dir);
        try {
            await fs.stat(fullCaminho);
        }
        catch {
            if (fullOpcoes.verbose) {
                log.aviso(messages.PROGRESSO_IMPORTS.diretorioNaoEncontrado(dir));
            }
            continue;
        }
        for await (const fileCaminho of walkDirectory(fullCaminho)) {
            const resultado = await processarArquivo(fileCaminho, fullOpcoes);
            if (resultado.modificado || resultado.erro) {
                resultados.push(resultado);
                if (fullOpcoes.verbose) {
                    if (resultado.modificado) {
                        log.sucesso(messages.PROGRESSO_IMPORTS.arquivoProcessado(resultado.arquivo, resultado.correcoes.length));
                    }
                    if (resultado.erro) {
                        log.erro(messages.PROGRESSO_IMPORTS.arquivoErro(resultado.arquivo, resultado.erro));
                    }
                }
            }
        }
    }
    return resultados;
}
export function gerarRelatorioCorrecoes(resultados) {
    const modificados = resultados.filter(raiz => raiz.modificado);
    const comErro = resultados.filter(raiz => raiz.erro);
    const totalCorrecoes = modificados.reduce((sum, raiz) => sum + raiz.correcoes.length, 0);
    const linhas = ['# Relatório de Correções de Imports\n', `Arquivos processados: ${resultados.length}`, `Arquivos modificados: ${modificados.length}`, `Total de correções: ${totalCorrecoes}`, `Erros: ${comErro.length}\n`];
    if (modificados.length > 0) {
        linhas.push('## Arquivos Modificados\n');
        for (const resultado of modificados) {
            linhas.push(`### ${resultado.arquivo}`);
            linhas.push(`**Correções:** ${resultado.correcoes.length}\n`);
            const porTipo = resultado.correcoes.reduce((acc, elem) => {
                acc[elem.tipo] = (acc[elem.tipo] || 0) + 1;
                return acc;
            }, {});
            for (const [tipo, count] of Object.entries(porTipo)) {
                linhas.push(`- ${tipo}: ${count}`);
            }
            linhas.push('');
        }
    }
    if (comErro.length > 0) {
        linhas.push('## Erros\n');
        for (const resultado of comErro) {
            linhas.push(`- **${resultado.arquivo}**: ${resultado.erro}`);
        }
        linhas.push('');
    }
    return linhas.join('\n');
}
export async function corrigirImports(dirs = ['src', 'tests'], options = {}) {
    log.fase?.(messages.MENSAGENS_IMPORTS.titulo);
    console.log();
    const resultados = await executarZeladorImports(dirs, {
        ...options,
        verbose: true
    });
    const modificados = resultados.filter(raiz => raiz.modificado);
    const totalCorrecoes = modificados.reduce((sum, raiz) => sum + raiz.correcoes.length, 0);
    const comErro = resultados.filter(raiz => raiz.erro);
    const resumo = messages.gerarResumoImports({
        processados: resultados.length,
        modificados: modificados.length,
        totalCorrecoes,
        erros: comErro.length,
        dryRun: options.dryRun ?? false
    });
    for (const linha of resumo) {
        if (linha === '') {
            console.log();
        }
        else if (linha.includes('[OK]')) {
            log.sucesso(linha);
        }
        else if (linha.includes('[AVISO]')) {
            log.aviso(linha);
        }
        else {
            log.info(linha);
        }
    }
}
//# sourceMappingURL=caretaker-imports.js.map