package click.kamil.examples.enterprise.api;

import click.kamil.examples.enterprise.constants.OrderEvents;
import lombok.RequiredArgsConstructor;
import org.springframework.statemachine.StateMachine;
import org.springframework.web.servlet.HandlerInterceptor;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@RequiredArgsConstructor
public class SecurityInterceptor implements HandlerInterceptor {

    private final StateMachine<String, String> stateMachine;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        stateMachine.sendEvent(OrderEvents.AUDIT);
        return true;
    }
}
