package click.kamil.examples.statemachine.inheritanceextrafunctionsstate3;

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

class F2StateMachineConfiguration extends AbstractFStateMachineConfiguration {
    @Override
    protected void addAdditionalStates(StateConfigurer<States, Events> states) {
        states.state(States.STATE_EXTRA_1_1);
        states.state(States.STATE_EXTRA_1_2);
        states.state(States.STATE_EXTRA_1);
        states.state(States.STATE_EXTRA_1_3);
    }

    @Override
    protected void addAdditionalCancellationTransitions(StateMachineTransitionConfigurer<States, Events> transitions) {
        addAllCancellationTransitionsForSource(transitions, States.STATE_EXTRA_1_1);
        addAllCancellationTransitionsForSource(transitions, States.STATE_EXTRA_1_2);
        addAllCancellationTransitionsForSource(transitions, States.STATE_EXTRA_1);
    }

    @Override
    protected void addAdditionalTransitions(ExternalTransitionConfigurer<States, Events> transitions) throws Exception {
        transitions
                .and()
                .withExternal().event(Events.EVENT_1_1)
                .source(States.STATE9)
                .target(States.STATE_EXTRA_1_1)
                .and()
                .withChoice()
                .source(States.STATE_EXTRA_1_2)
                .first(States.STATE_EXTRA_1_1, guardEventHeaderEquals("header1", "foo"))
                .last(States.STATE_EXTRA_1_3)
                .and()
                .withExternal()
                .source(States.STATE_EXTRA_1_3)
                .event(Events.EVENT_1_2)
                .target(States.STATE_EXTRA_1);
    }

}
