package com.yfyy.yingtan.util;

import com.dtflys.forest.Forest;
import com.dtflys.forest.http.ForestResponse;
import com.yfyy.yingtan.ApplicationCons;
import com.yfyy.yingtan.bean.request.NonLoraDataReqBean;
import com.yfyy.yingtan.bean.request.SyncReqBean;
import com.yfyy.yingtan.bean.response.BaseResBean;
import com.yfyy.yingtan.bean.response.LoginResBean;
import com.yfyy.yingtan.http.YingtanClient;

import java.util.List;
import java.util.Map;

/**
 * 网络请求工具类
 */
public class HttpUtil {

    // 上线
    public static void onlineAndReportProperty(List<SyncReqBean> syncReqBeanList, NonLoraDataReqBean nonLoraDataReqBean){
        YingtanClient yingtanClient = Forest.client(YingtanClient.class);
        ForestResponse<BaseResBean<LoginResBean>> forestResponse = yingtanClient.login(ApplicationCons.loginName, ApplicationCons.password);
        BaseResBean<LoginResBean> beanBaseResBean = forestResponse.getResult();
        LoginResBean bean = beanBaseResBean.getData();
        ApplicationCons.token = forestResponse.getHeaderValue("Authenticator");
        System.out.println(bean);

//        List<SyncReqBean> syncReqBeanList = new ArrayList<>();
//        syncReqBeanList.add(getBean1());
        Map syncMap = yingtanClient.sync(ApplicationCons.token, syncReqBeanList);
        System.out.println("数据上报：" + nonLoraDataReqBean.getDeviceId());
        System.out.println(syncMap);

        Map nonLoraDataMap = yingtanClient.NonLoraData(ApplicationCons.token, nonLoraDataReqBean);
        System.out.println(nonLoraDataMap);


    }

}
