package click.kamil.springstatemachineexporter.ast.app;

import click.kamil.springstatemachineexporter.model.Transition;
import click.kamil.springstatemachineexporter.ast.common.CodebaseContext;
import lombok.Getter;
import org.eclipse.jdt.core.dom.TypeDeclaration;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class StateMachineAggregator {
    private final CodebaseContext context;
    private final StateMachineAdapterParser adapterParser;

    @Getter
    private final Set<String> initialStates = new HashSet<>();
    @Getter
    private final Set<String> endStates = new HashSet<>();

    public StateMachineAggregator(CodebaseContext context) {
        this.context = context;
        this.adapterParser = new StateMachineAdapterParser(context);
    }

    public List<Transition> aggregateTransitions(TypeDeclaration startClass) {
        return adapterParser.parseTransitions(startClass);
    }

    public void aggregateStates(TypeDeclaration startClass) {
        StateMachineAdapterParser.AdapterStates states = adapterParser.parseStates(startClass);
        this.initialStates.clear();
        this.initialStates.addAll(states.initialStates());
        this.endStates.clear();
        this.endStates.addAll(states.endStates());
    }
}
