package com.stm.asset.http;

import com.stm.asset.base.StmApplication;
import com.stm.asset.utils.PropertyUtil;
import com.stm.asset.utils.SystemUtil;

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

/**
 * 类名称：RequestParams
 * 类描述：网络请求参数封装
 * 创建人：story
 * 创建时间：2021-12-10 17:15
 */
public class RequestParams {

    private Map<String, String> headers;
    private Map<String, String> bodyParams;
    
    public RequestParams() {
        addCommonHead();
    	addCommonParams();
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public Map<String, String> getBodyParams() {
        return bodyParams;
    }

    /**
     * 添加header
     */
    public void addHeader(String name, String value) {
        if (this.headers == null) {
            this.headers = new HashMap<>();
        }
        this.headers.put(name, value);
    }

    /**
     * 添加body参数
     */
    public void addBodyParameter(String name, String value) {
        if (bodyParams == null) {
            bodyParams = new HashMap<>();
        }
        bodyParams.put(name, value);
    }

    private void addCommonHead() {
        if (this.headers == null) {
            this.headers = new HashMap<>();
        }
        long currentTime = System.currentTimeMillis();
        headers.put("Current-Time", String.valueOf(currentTime));
        headers.put("Authenticator-Data", MD5Util.getAuthenticator(currentTime));
        if (StmApplication.getInstance().getUserInfo() != null) {
            headers.put("Acess-Token", PropertyUtil.getAccessToken(StmApplication.getInstance().getApplicationContext()));
        }
    }

    private void addCommonParams(){
    	if (bodyParams == null) {
            bodyParams = new HashMap<>();
        }
        bodyParams.put("machinecode", "phone");
        bodyParams.put("machinetype", "phone");
        bodyParams.put("channelcode", "VUE");
        bodyParams.put("terminalcode", "fee");
        bodyParams.put("platform", PropertyUtil.getHttpPlatform(StmApplication.getInstance().getApplicationContext()));
    }

}