package click.kamil.examples.statemachine.inheritanceextrafunctionsstate3;

import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
import org.springframework.statemachine.config.configurers.ExternalTransitionConfigurer;

import java.util.function.Consumer;
import java.util.stream.Stream;

class AbstractStateMachineConfiguration<S,E> extends StateMachineConfigurerAdapter<S,E> {
    protected void addTransitionForMultipleEvents(
            StateMachineTransitionConfigurer<S, E> transitions,
            S source,
            S target,
            Consumer<ExternalTransitionConfigurer<S,E>> transitionCustomizer,
            E... events) {
        Stream.of(events).forEach(event -> {
            try {
                ExternalTransitionConfigurer<S, E> transitionConfigurer =
                        transitions.withExternal().event(event).source(source).target(target);
                transitionCustomizer.accept(transitionConfigurer);
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        });
    }
}
