package click.kamil.springstatemachineexporter.analysis.enricher;

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

/**
 * Final enrichment step: fail fast when enum identifiers in the analysis model are not
 * package-canonical. Disable with {@code -Danalyzer.canonical-form-validation.enabled=false}.
 */
@Slf4j
public class AnalysisCanonicalFormEnricher implements AnalysisEnricher {

    private final boolean enabled;

    public AnalysisCanonicalFormEnricher() {
        this.enabled = Boolean.parseBoolean(
                System.getProperty("analyzer.canonical-form-validation.enabled", "true"));
    }

    @Override
    public void enrich(AnalysisResult result, CodebaseContext context, CodebaseIntelligenceProvider intelligence) {
        if (!enabled || result == null || context == null) {
            return;
        }
        log.debug("Validating canonical enum identifiers for {}", result.getName());
        AnalysisCanonicalFormValidator.enforce(result, context);
    }
}
