package click.kamil.examples.statemachine.layered.order.config;

import click.kamil.examples.statemachine.layered.order.OrderState;
import click.kamil.examples.statemachine.layered.order.OrderTransitionEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.config.EnableStateMachineFactory;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;

@Configuration
@EnableStateMachineFactory(name = "orderStateMachineFactory")
public class StandardOrderStateMachineConfiguration extends AbstractOrderStateMachineConfiguration {

    @Override
    protected void configureAdditionalStates(StateMachineStateConfigurer<OrderState, OrderTransitionEvent> states)
            throws Exception {
        states.withStates().state(OrderState.CANCELLED);
    }

    @Override
    protected void configureAdditionalTransitions(
            StateMachineTransitionConfigurer<OrderState, OrderTransitionEvent> transitions) throws Exception {
        transitions
                .withExternal()
                .source(OrderState.PAID)
                .target(OrderState.CANCELLED)
                .event(OrderTransitionEvent.CANCEL);
    }
}
