package com.caliverse.admin.global.component.manager;

import com.caliverse.admin.domain.entity.log.LogAction;
import com.caliverse.admin.global.common.utils.CommonUtils;
import org.springframework.stereotype.Component;

@Component
public class BusinessProcessIdManager {
    private static final ThreadLocal<String> processId = new ThreadLocal<>();
    private static final ThreadLocal<LogAction> businessAction = new ThreadLocal<>();

    public String getCurrentProcessId() {
        return processId.get();
    }

    public LogAction getCurrentAction() {
        return businessAction.get();
    }

    public String createNewProcessId() {
        String newId = CommonUtils.getCreateGuId();
        processId.set(newId);
        return newId;
    }

    public void setCurrentAction(LogAction action) {
        businessAction.set(action);
    }

    public void clear() {
        processId.remove();
        businessAction.remove();
    }

    public boolean hasProcessId() {
        return processId.get() != null;
    }
}
