package com.stm.asset.http;

import com.stm.asset.base.InterfaceKey;
import com.stm.asset.json.CommonMapJson;
import com.stm.asset.json.CommonStringJson;
import com.stm.asset.json.ListUserInfo;
import com.stm.asset.json.TaskListJson;
import com.stm.asset.utils.SM2Util;

/**
 * 类名称：HttpService
 * 类描述：封装请求服务
 * 创建人：story
 * 创建时间：2021-12-11 16:00
 */
public class HttpService {

    private static HttpService instance;

    private HttpService() {}

    public static HttpService getInstance() {
        if (instance == null) {
            instance = new HttpService();
        }
        return instance;
    }

    public void unionLoginApp(String accout, String password, RequestCallback<CommonStringJson> requestCallback) {
        RequestParams params = new RequestParams();
        params.addBodyParameter("username", SM2Util.encrypt(accout));
        params.addBodyParameter("password", SM2Util.encrypt(password));
        HttpUtil.getInstance().sendJson(InterfaceKey.UNIONLOGINAPP, params, requestCallback);
    }

    public void quryPageHomeUserInfo(String accessToken, RequestCallback<ListUserInfo> requestCallback) {
        RequestParams params = new RequestParams();
        params.addHeader("Acess-Token", accessToken);
        params.addBodyParameter("accessToken", accessToken);
        HttpUtil.getInstance().sendJson(InterfaceKey.QURYPAGEHOMEUSERINFO, params, requestCallback);
    }

    public void queryAppVersionApp(RequestCallback<CommonMapJson> requestCallback) {
        RequestParams params = new RequestParams();
        HttpUtil.getInstance().sendJson(InterfaceKey.QUERYVERSIONAPP, params, requestCallback);
    }

    public void queryInventoryMainPage(int pageNum, int pageSize, RequestCallback<TaskListJson> requestCallback) {
        RequestParams params = new RequestParams();
        params.addBodyParameter("pageNum", String.valueOf(pageNum));
        params.addBodyParameter("pageSize", String.valueOf(pageSize));
        params.addBodyParameter("pageStatus", "amsInventoryExecution");
        params.addBodyParameter("inventoryType", "0");
        HttpUtil.getInstance().sendJson(InterfaceKey.QUERYINVENTORYMAINPAGE, params, requestCallback);
    }

    public void scanInventory(String mainId, String numberList, RequestCallback<CommonStringJson> requestCallback) {
        RequestParams params = new RequestParams();
        params.addBodyParameter("mainId", mainId);
        params.addBodyParameter("assetNumListStr", numberList);
        HttpUtil.getInstance().sendJson(InterfaceKey.SCANINVENTORY, params, requestCallback);
    }

}
