package click.kamil.examples.statemachine.polymorphic;
import org.springframework.statemachine.StateMachine;
import org.springframework.stereotype.Service;
import org.springframework.messaging.support.MessageBuilder;

@Service
public class OrderService {
    private final StateMachine<OrderStates, OrderEvents> sm;

    public OrderService(StateMachine<OrderStates, OrderEvents> sm) { this.sm = sm; }

    public void processEvent(BaseEvent event) {
        sm.sendEvent(event.getType());
    }
    
    public void processPayloadEvent(Object payload) {
        sm.sendEvent(MessageBuilder.withPayload(payload).build());
    }

    public void processCustomEvent(CustomCodeEventInterface event) {
        sm.sendEvent(event.resolveEventCode());
    }
}
