package ai.pai.client.utils;

import android.content.Context;
import android.os.AsyncTask;

import com.android.common.http.HttpUtils;
import com.android.common.utils.LogHelper;

import java.util.HashMap;

import ai.pai.client.BuildConfig;


public  class HttpPostTask extends AsyncTask<String,Integer,Boolean> {

    private Context context;
    private HashMap<String,String> httpParams;

    public HttpPostTask(Context context, HashMap<String,String> httpParams){
        this.context = context;
        this.httpParams = httpParams;
    }

    @Override
    protected Boolean doInBackground(String... params) {
        String rootUrl = params[0];
        if(rootUrl.contains("?")){
            rootUrl+="&platform=android";
        }else{
            rootUrl+="?platform=android";
        }
        rootUrl+="&version="+BuildConfig.VERSION_NAME;
        rootUrl+="&channel="+"guanwang";
        String response= HttpUtils.doHttpPost(rootUrl,httpParams);
        LogHelper.d("czy","request url =="+ rootUrl + "\n");
        LogHelper.d("czy","response == \n"+response);
        return parseResponse(context,response);
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        if(result){
            onPostSuccess(context);
        }else{
            onPostFail(context);
        }
    }

    protected  boolean parseResponse(Context context,String response){return true;}

    protected void onPostFail(Context context){ }

    protected  void onPostSuccess(Context context){ }



}
