package click.kamil.springstatemachineexporter.analysis.enricher;

import click.kamil.springstatemachineexporter.analysis.model.AnalysisResult;
import click.kamil.springstatemachineexporter.analysis.model.CallChain;
import click.kamil.springstatemachineexporter.analysis.model.CodebaseMetadata;
import click.kamil.springstatemachineexporter.analysis.service.CodebaseIntelligenceProvider;
import click.kamil.springstatemachineexporter.ast.common.CodebaseContext;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class CallChainEnricher implements AnalysisEnricher {

    @Override
    public void enrich(AnalysisResult result, CodebaseContext context, CodebaseIntelligenceProvider intelligence) {
        log.info("Enriching {} with call chains", result.getName());
        
        List<CallChain> chains = intelligence.findCallChains(
                result.getMetadata().getEntryPoints(),
                result.getMetadata().getTriggers()
        );
        
        result.addMetadata(CodebaseMetadata.builder()
                .callChains(chains)
                .build());
    }
}
