package com.yidianling.ydlcommon.custom.http.api;

import com.google.gson.Gson;
import com.yidianling.ydlcommon.custom.data.MustUP;
import com.yidianling.ydlcommon.custom.http.BaseAPIResponse;
import com.yidianling.ydlcommon.custom.http.BaseResponse;
import com.yidianling.ydlcommon.custom.http.FormatText;
import com.yidianling.ydlcommon.custom.http.YdlRetrofitUtils;
import com.yidianling.ydlcommon.custom.http.params.ActionDataBean;
import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

import java.util.List;

/**
 * 模块请求工具类
 * Created by hgw on 2018/1/23.
 */

public class ApiRequestUtil {
    //强制更新埋点
    public static Observable<BaseResponse<MustUP>> appWillUp(Command.APPWillUp cmd) {
        List<FormatText> list = YdlRetrofitUtils.getPostList(cmd);
        return YdlRetrofitUtils.getRxRetrofit().create(NetApiStore.class).appWillUp(YdlRetrofitUtils.getMaps(list));
    }

    //上传错误日志信息
    public static Observable<BaseResponse> upLoadLoginStatus(Command.upLoadLoginStatus cmd) {
        List<FormatText> list = YdlRetrofitUtils.getPostList(cmd);
        return YdlRetrofitUtils.getRxRetrofit().create(NetApiStore.class).upLoadLoginStatus(YdlRetrofitUtils.getMaps(list));
    }
    /**
     * 上传webview初始化及加载url时间接口
     *
     * @param param
     * @return
     */
    public static Observable<BaseResponse> uploadWebViewTime(String param) {
        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), param);
        return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_TEMP_JAVA_URL).build().create(NetApiStore.class).uploadWebViewTime(body);
    }

    /**
     * 行为数据埋点统计接口
     */
    public static Observable<BaseAPIResponse<String>> actionDataCount(ActionDataBean actionDataParams) {
        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), new Gson().toJson(actionDataParams));
        return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.ACTION_URL).build().create(NetApiStore.class).actionDataCount(body);
    }
}
