package cn.axzo.workflow.client.config.context;

/**
 * HTTP 请求的 Header 上下文
 *
 * @author wangli
 * @since 2024/2/4 15:46
 */
public class RequestHeaderContext {

    private static final ThreadLocal<RequestHeaderContext> REQUEST_HEADER_CONTEXT_THREAD_LOCAL = new ThreadLocal<>();
    private String apiVersion;
    private String serverName;

    public String getApiVersion() {
        return apiVersion;
    }

    public String getServerName() {
        return serverName;
    }

    public static RequestHeaderContext getInstance() {
        return REQUEST_HEADER_CONTEXT_THREAD_LOCAL.get();
    }

    public void setContext(RequestHeaderContext context) {
        REQUEST_HEADER_CONTEXT_THREAD_LOCAL.set(context);
    }

    public static void clean() {
        REQUEST_HEADER_CONTEXT_THREAD_LOCAL.remove();
    }

    private RequestHeaderContext(RequestHeaderContextBuild requestHeaderContextBuild) {
        this.apiVersion = requestHeaderContextBuild.apiVersion;
        this.serverName = requestHeaderContextBuild.serverName;
        setContext(this);
    }

    public static class RequestHeaderContextBuild {
        private String apiVersion;
        private String serverName;

        public RequestHeaderContextBuild apiVersion(String apiVersion) {
            this.apiVersion = apiVersion;
            return this;
        }

        public RequestHeaderContextBuild serverName(String serverName) {
            this.serverName = serverName;
            return this;
        }

        public RequestHeaderContext bulid() {
            return new RequestHeaderContext(this);
        }
    }
}


