package com.yutou.okhttp;

import com.yutou.qqbot.utlis.ConfigTools;
import okhttp3.Request;

import java.util.HashMap;

public class ParamsContext {
    private IRequestParam iRequestParam;
    private Request request;
    private HashMap<String, String> map;
    private HashMap<String, String> headerMap;

    public ParamsContext(HashMap<String, String> map, Request request) {
        if (map == null) {
            map = new HashMap<>();
        }
        this.map = map;
        this.request = request;
        this.headerMap = new HashMap<>();
    }

    public ParamsContext(HashMap<String, String> headerMap, HashMap<String, String> map, Request request) {
        if (map == null) {
            map = new HashMap<>();
        }
        this.map = map;
        this.request = request;
        this.headerMap = headerMap;
    }

    public Request getInRequest() {
        switch (request.method()) {
            case "GET":
                iRequestParam = new GetRequestParams();
                break;
            case "POST":
                iRequestParam = new PostRequestParams();
                break;
        }
        headerMap.put("User-Agent", ConfigTools.getUserAgent());
        return iRequestParam.getRequest(headerMap, map, request);
    }
}