package cn.axzo.msg.center.message.service.card;

import cn.axzo.msg.center.utils.UUIDUtil;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yanglin
 */
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class CardRequestContext<T> {

    private final String batchNo = UUIDUtil.uuidString();
    private final T request;
    private final Map<String, Object> logContents = new HashMap<>();

    public static <T> CardRequestContext<T> create(T request) {
        CardRequestContext<T> context = new CardRequestContext<>(request);
        context.addLogContent("request", request);
        return context;
    }

    public CardRequestContext<T> addLogContent(String key, Object value) {
        if (value == null || logContents.containsKey(key))
            return this;
        logContents.put(key, value);
        return this;
    }

}