package com.huimv.video.dhicc.test.request.XunZhengRequest.Sg;

import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.huimv.video.dhicc.icc.CommonConstant;
import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo;
import com.huimv.video.dhicc.test.constant.Constant;
import com.huimv.video.dhicc.test.request.BaseRequest;
import com.huimv.video.dhicc.test.utils.HttpURLConnectionUtil;
import com.huimv.video.dhicc.test.utils.HttpsURLConnectionUtil;
import com.huimv.video.dhicc.test.utils.UrlUtil;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class XunZhengCountRequestSg extends BaseRequest {

    private Integer farmId;

    private Integer pageNum;

    private Integer pageSize;

    private String alarmStartDateString;

    private String alarmEndDateString;

    private Integer eventType;

    public XunZhengCountRequestSg(OauthConfigBaseInfo oauthConfigBaseInfo){
        super(oauthConfigBaseInfo, Constant.HTTP_POST,oauthConfigBaseInfo.getHttpConfigInfo().getPrefixUrl() + Constant.EVENT_COUNT_URL, true);
    }

    @Override
    public String doAction() {
        //重置url信息，替换版本号
        this.setUrl(UrlUtil.dealVersion(this.getUrl()));
        //设置请求参数
        setBody();
        //发送请求
        String res = isEnableHttpTest() ? HttpURLConnectionUtil.doPost(this.getUrl(), this.getBody(), this.getHeader()) : HttpsURLConnectionUtil.doPost(this.getUrl(), this.getBody(), this.getHeader());

        return res;
    }

    private void setBody() {
        //设置请求参数
        Map<String, Object> map = new HashMap<>();
        map.put("alarmStartDateString", this.alarmStartDateString);
        map.put("alarmEndDateString", this.alarmEndDateString);
        map.put("alarmType", 303);
        map.put("dbType", 0);
        map.put("deviceCategory", 1);
        if (this.eventType == 1){
            map.put("nodeCodeList", CommonConstant.Sg_SiZhuChannle);
        }else if (this.eventType == 2){
            map.put("nodeCodeList", CommonConstant.Sg_DoorChannle);
        }else if (this.eventType == 3){
            map.put("nodeCodeList", CommonConstant.Sg_XunZhengChannle);
        }else if (this.eventType == 4){
            map.put("nodeCodeList", CommonConstant.Sg_MaiZhuChannle);
        }else {
            map.put("nodeCodeList", CommonConstant.Sg_XiXiaoChannle);
        }
        this.setBody(JSON.toJSONString(map));

    }

    public boolean isEnableHttpTest() {
        return super.getOauthConfigBaseInfo().getHttpConfigInfo().isEnableHttpTest();
    }
}
