package click.kamil.enterprise.machines.document;

import click.kamil.enterprise.core.AbstractStateMachine;
import click.kamil.enterprise.core.TransitionContext;
import org.springframework.stereotype.Component;

@Component
public class DocumentStateMachine extends AbstractStateMachine<DocumentState, DocumentEvent> {

    public DocumentStateMachine() {
        super(DocumentState.DRAFT);
    }

    @Override
    public String getMachineType() {
        return "DOCUMENT";
    }

    @Override
    protected void configureTransitions() {
        addTransition(DocumentEvent.SUBMIT, DocumentState.IN_REVIEW);
        addTransition(DocumentEvent.APPROVE, DocumentState.APPROVED);
        addTransition(DocumentEvent.REJECT, DocumentState.DRAFT);
    }

    @Override
    protected void onTransition(DocumentState from, DocumentState to, DocumentEvent event, TransitionContext<?> context) {
        System.out.println("[Document] Document modified by " + context.getUserId() + ". Now " + to);
    }
}
