export function scoreArquetipo(def, _arquivos, _sinaisAvancados) {
    return {
        nome: def.nome,
        descricao: def.descricao ?? '',
        score: 0,
        confidence: 0,
        matchedRequired: [],
        missingRequired: [],
        matchedOptional: [],
        dependencyMatches: [],
        filePadraoMatches: [],
        forbiddenPresent: [],
        anomalias: []
    };
}
export function extrairSinaisAvancados(fileEntries, packageJson, _p0, _baseDir, _arquivos) {
    const hasIdNome = (node) => {
        return typeof node === 'object' && node !== null && 'id' in node && typeof node.id?.name === 'string';
    };
    const sinais = {
        funcoes: 0,
        imports: [],
        variaveis: 0,
        tipos: [],
        classes: 0,
        frameworksDetectados: [],
        dependencias: [],
        scripts: [],
        pastasPadrao: [],
        arquivosPadrao: [],
        arquivosConfiguracao: [],
        padroesArquiteturais: [],
        tecnologiasDominantes: [],
        complexidadeEstrutura: 'baixa',
        tipoDominante: 'desconhecido'
    };
    const padroesDetectados = new Set();
    const tecnologias = new Map();
    for (const fe of fileEntries) {
        let body = [];
        if (fe.ast && 'node' in fe.ast && fe.ast.node && fe.ast.node.type === 'Program' && Array.isArray(fe.ast.node.body)) {
            body = fe.ast.node.body;
        }
        const conteudo = fe.content || '';
        const relPath = fe.relPath.toLowerCase();
        if (relPath.includes('controller') || relPath.includes('model') || relPath.includes('view')) {
            padroesDetectados.add('mvc');
        }
        if (relPath.includes('/domain/') || relPath.includes('/entities/') || relPath.includes('value-object')) {
            padroesDetectados.add('clean-arch-domain');
        }
        if (relPath.includes('/application/') || relPath.includes('/use-cases') || relPath.includes('/ports/')) {
            padroesDetectados.add('clean-arch-application');
        }
        if (relPath.includes('/infrastructure/') || relPath.includes('/infra/')) {
            padroesDetectados.add('clean-arch-infrastructure');
        }
        if (relPath.includes('/presentation/') || relPath.includes('/presenters/')) {
            padroesDetectados.add('clean-arch-presentation');
        }
        if (relPath.includes('usecase') || relPath.includes('use-case') || relPath.includes('interactor')) {
            padroesDetectados.add('use-case');
        }
        if (relPath.includes('entity') || relPath.includes('aggregate')) {
            padroesDetectados.add('domain-entity');
        }
        if (relPath.includes('/services/') && !relPath.includes('/services/')) {
        }
        if (relPath.match(/services\/[^/]+\//)) {
            padroesDetectados.add('microservice-boundary');
        }
        if (relPath.includes('/gateway') || relPath.includes('api-gateway')) {
            padroesDetectados.add('api-gateway');
        }
        if (relPath.includes('/events/') || relPath.includes('/messaging') || relPath.includes('/queues')) {
            padroesDetectados.add('event-driven');
        }
        if (relPath.includes('/discovery') || relPath.includes('consul') || relPath.includes('eureka')) {
            padroesDetectados.add('service-discovery');
        }
        if (relPath.includes('/docker') || relPath.endsWith('dockerfile') || relPath.includes('docker-compose')) {
            padroesDetectados.add('containerized');
        }
        if (relPath.includes('kubernetes') || relPath.includes('k8s')) {
            padroesDetectados.add('orchestrated');
        }
        if (relPath.includes('/shared/') || relPath.includes('/common/')) {
            padroesDetectados.add('shared-library');
        }
        if (relPath.includes('/monitoring') || relPath.includes('/health') || relPath.includes('/metrics')) {
            padroesDetectados.add('monitoring');
        }
        if (relPath.includes('repository') || relPath.includes('service')) {
            padroesDetectados.add('repository-service');
        }
        if (conteudo.includes('useState') || conteudo.includes('useEffect')) {
            tecnologias.set('react-hooks', (tecnologias.get('react-hooks') || 0) + 1);
        }
        if (conteudo.includes('async') && conteudo.includes('await')) {
            padroesDetectados.add('async-await');
        }
        if (conteudo.includes('interface') || conteudo.includes('type ')) {
            tecnologias.set('typescript-advanced', (tecnologias.get('typescript-advanced') || 0) + 1);
        }
        if (conteudo.includes('commander') || conteudo.includes('yargs') || relPath.includes('bin/')) {
            padroesDetectados.add('cli-patterns');
        }
        sinais.funcoes += body.filter((node) => node.type === 'FunctionDeclaration').length;
        const imports = body.filter((node) => node.type === 'ImportDeclaration');
        sinais.imports.push(...imports.map(indice => indice.source.value));
        sinais.variaveis += body.filter((node) => node.type === 'VariableDeclaration').length;
        sinais.tipos.push(...body.filter((node) => ['TSTypeAliasDeclaration', 'TSInterfaceDeclaration', 'TSEnumDeclaration'].includes(node.type)).map(node => hasIdNome(node) ? node.id.name : undefined).filter((valor) => typeof valor === 'string'));
        sinais.classes += body.filter((node) => node.type === 'ClassDeclaration').length;
        for (const indice of imports) {
            if (typeof indice.source.value === 'string') {
                const importSource = indice.source.value.toLowerCase();
                if (importSource.includes('react') || importSource.includes('vue') || importSource.includes('angular')) {
                    tecnologias.set('frontend-framework', (tecnologias.get('frontend-framework') || 0) + 1);
                }
                if (importSource.includes('express') || importSource.includes('fastify') || importSource.includes('nestjs')) {
                    tecnologias.set('backend-framework', (tecnologias.get('backend-framework') || 0) + 1);
                }
                if (importSource.includes('prisma') || importSource.includes('mongoose') || importSource.includes('typeorm')) {
                    tecnologias.set('orm', (tecnologias.get('orm') || 0) + 1);
                }
                if (importSource.includes('jest') || importSource.includes('vitest') || importSource.includes('mocha')) {
                    tecnologias.set('testing-framework', (tecnologias.get('testing-framework') || 0) + 1);
                }
                if (/express|react|next|electron|discord\.js|telegraf/.test(importSource)) {
                    sinais.frameworksDetectados.push(indice.source.value);
                }
            }
        }
        const rel = fe.relPath.replace(/\\/g, '/');
        if (/src\/controllers|pages|api|prisma|packages|apps|src\/routes|src\/services|src\/repositories/.test(rel)) {
            sinais.pastasPadrao.push(rel);
        }
        if (/main\.js|index\.ts|bot\.ts|electron\.js|server\.js|app\.js/.test(rel)) {
            sinais.arquivosPadrao.push(rel);
        }
        if (/tsconfig\.json|turbo\.json|pnpm-workspace\.yaml|webpack\.config|rollup\.config|vite\.config/.test(rel)) {
            sinais.arquivosConfiguracao.push(rel);
        }
    }
    sinais.padroesArquiteturais = Array.from(padroesDetectados);
    const temDomain = padroesDetectados.has('clean-arch-domain') || padroesDetectados.has('domain-entity');
    const temApplication = padroesDetectados.has('clean-arch-application') || padroesDetectados.has('use-case');
    const temInfrastructure = padroesDetectados.has('clean-arch-infrastructure');
    const temPresentation = padroesDetectados.has('clean-arch-presentation');
    sinais.camadasCleanArch = {
        domain: temDomain,
        application: temApplication,
        infrastructure: temInfrastructure,
        presentation: temPresentation
    };
    sinais.padroesCleanArch = Array.from(padroesDetectados)
        .filter(p => p.startsWith('clean-arch') || p === 'use-case' || p === 'domain-entity');
    const serviceBoundaries = new Set(fileEntries
        .map(fe => {
        const match = fe.relPath.match(/services\/([^/]+)/);
        return match ? match[1] : null;
    })
        .filter((s) => s !== null));
    sinais.boundariesServicos = Array.from(serviceBoundaries);
    sinais.padroesDistribuidos = Array.from(padroesDetectados)
        .filter(p => ['microservice-boundary', 'api-gateway', 'event-driven', 'service-discovery',
        'containerized', 'orchestrated', 'shared-library', 'monitoring'].includes(p));
    sinais.mensageriaDetectada = fileEntries
        .filter(fe => {
        const c = fe.content?.toLowerCase() || '';
        return c.includes('kafkajs') || c.includes('amqplib') || c.includes('ioredis') ||
            c.includes('bull') || c.includes('bullmq') || c.includes('nats') ||
            c.includes('eventemitter') || c.includes('pubsub');
    })
        .map(fe => fe.relPath);
    let maxContagem = 0;
    let dominante = 'desconhecido';
    for (const [tech, count] of tecnologias) {
        if (count > maxContagem) {
            maxContagem = count;
            dominante = tech;
        }
    }
    sinais.tecnologiasDominantes = Array.from(tecnologias.keys());
    sinais.tipoDominante = dominante;
    const totalArquivos = fileEntries.length;
    const totalPastas = new Set(fileEntries.map(fe => fe.relPath.split('/').slice(0, -1).join('/'))).size;
    if (totalArquivos > 100 || totalPastas > 20) {
        sinais.complexidadeEstrutura = 'alta';
    }
    else if (totalArquivos > 50 || totalPastas > 10) {
        sinais.complexidadeEstrutura = 'media';
    }
    else {
        sinais.complexidadeEstrutura = 'baixa';
    }
    if (packageJson) {
        sinais.dependencias.push(...Object.keys(packageJson.dependencies || {}));
        sinais.scripts.push(...Object.keys(packageJson.scripts || {}));
    }
    sinais.imports = Array.from(new Set(sinais.imports));
    sinais.frameworksDetectados = Array.from(new Set(sinais.frameworksDetectados));
    sinais.pastasPadrao = Array.from(new Set(sinais.pastasPadrao));
    sinais.arquivosPadrao = Array.from(new Set(sinais.arquivosPadrao));
    sinais.arquivosConfiguracao = Array.from(new Set(sinais.arquivosConfiguracao));
    sinais.tipos = Array.from(new Set(sinais.tipos));
    return sinais;
}
export const scoreArquetipoAvancado = scoreArquetipo;
//# sourceMappingURL=signals-project-advanced.js.map