package click.kamil.examples.statemachine.extended.service;

import lombok.RequiredArgsConstructor;
import org.springframework.statemachine.StateMachine;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Service
@RequiredArgsConstructor
public class ReactiveOrderService {

    private final StateMachine<String, String> stateMachine;

    public Mono<Void> processReactive(String orderId) {
        return Mono.just(orderId)
                .doOnNext(id -> {
                    // Hidden trigger inside a lambda!
                    stateMachine.sendEvent("REACTIVE_EVENT");
                })
                .then();
    }
}
