package click.kamil.examples.enterprise.service;

import lombok.RequiredArgsConstructor;
import org.springframework.statemachine.StateMachine;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import click.kamil.examples.enterprise.constants.OrderEvents;

@Service
@RequiredArgsConstructor
public class ReactivePaymentService {

    private final StateMachine<String, String> stateMachine;

    public Mono<Void> processPayment(String orderId) {
        return Mono.just(orderId)
                .doOnSuccess(id -> {
                    stateMachine.sendEvent(OrderEvents.PAY);
                })
                .then();
    }
}
