package com.baoshi.swms.net.subscribe;

import android.text.TextUtils;

import com.baoshi.swms.net.api.WasApi;
import com.baoshi.swms.net.constant.WasConstant;
import com.baoshi.swms.util.GlobalStorage;

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

/**
 * Was基础发布者
 *
 * @author Zhendong Zhou
 * @date 2021/12/3 14:42
 */
public class WasBaseSubscribe extends BaseSubscribe{
    private static WasApi okHttpApi;

    public static WasApi getOkHttpApi() {
        if (okHttpApi==null) {
            okHttpApi = newApi(WasConstant.BASE_URL, getHeaderParams(), WasApi.class);
        }
        return okHttpApi;
    }

    public static void refreshSingleton(){
        okHttpApi=null;
    }

    //设置表头
    protected static Map<String, String> getHeaderParams() {
        String token = GlobalStorage.getGlobalStorage().get("token");

        String timestamp;
        timestamp = String.valueOf(System.currentTimeMillis() / 1000);
        Map<String, String> params = new HashMap<>();
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        params.put("timestamp", timestamp);

        return params;
    }
}
