package cn.axzo.workflow.core.listener;

import cn.axzo.workflow.core.common.context.OperationContext;
import cn.hutool.json.JSONUtil;
import org.slf4j.MDC;

import static cn.azxo.framework.common.constatns.Constants.CTX_LOG_ID_MDC;

/**
 * 操作上下文的抽象实现
 *
 * @author wangli
 * @since 2024/4/9 14:21
 */
public abstract class AbstractBpmnEventListener<T extends OperationContext> implements OperationContext {

    private T context;

    @Override
    public void setContext(OperationContext context) {
        this.context = (T) context;
    }

    @Override
    public T getContext() {
        return context;
    }

    protected String getTraceId() {
        return MDC.get(CTX_LOG_ID_MDC);
    }

    protected String buildCacheKey(String apiUrl, Object request) {
        return apiUrl + JSONUtil.toJsonStr(request);
    }
}
