package com.seer.teach.teacher.stateMachine.action;

import lombok.extern.slf4j.Slf4j;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.action.Action;

@Slf4j
public class SafeAction<S, E> implements Action<S, E> {

    private final Action<S, E> delegate;

    public SafeAction(Action<S, E> delegate) {
        this.delegate = delegate;
    }

    @Override
    public void execute(StateContext<S, E> context) {
        try {
            delegate.execute(context);
        } catch (Exception e) {
            log.error("SafeActionWrapper 捕获 Action 异常，state={}, event={}",
                    context.getStateMachine().getState().getId(),
                    context.getEvent(), e);
        }
    }
}
