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

import click.kamil.examples.statemachine.layered.document.DocumentState;
import click.kamil.examples.statemachine.layered.document.DocumentTransitionEvent;
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 = "documentStateMachineFactory")
public class StandardDocumentStateMachineConfiguration extends AbstractDocumentStateMachineConfiguration {

    @Override
    protected void configureAdditionalStates(StateMachineStateConfigurer<DocumentState, DocumentTransitionEvent> states)
            throws Exception {
        states.withStates().state(DocumentState.REJECTED);
    }

    @Override
    protected void configureAdditionalTransitions(
            StateMachineTransitionConfigurer<DocumentState, DocumentTransitionEvent> transitions) throws Exception {
        transitions
                .withExternal()
                .source(DocumentState.SUBMITTED)
                .target(DocumentState.REJECTED)
                .event(DocumentTransitionEvent.REJECT);
    }
}
