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

import com.alibaba.fastjson.JSON;
import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo;
import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo02;
import com.huimv.video.dhicc.test.constant.Constant;
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.List;
import java.util.Map;

@Data
public class PersonListRequestHn extends BaseRequest02<String> {

    private Integer farmId;

    private String searchKey;

    private Integer pageNum;

    private Integer pageSize;

    private Integer departmentId;

    private Boolean isContain;

    private List<Integer> statusList;


    public PersonListRequestHn() {
    }

    public PersonListRequestHn(OauthConfigBaseInfo02 oauthConfigBaseInfo) {
        super(oauthConfigBaseInfo, Constant.HTTP_POST, oauthConfigBaseInfo.getHttpConfigInfo().getPrefixUrl() + Constant.CHANNEL_URL_PERSON_LIST, 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());
        //获取响应

       // PersonListResponseSg devicePageResponse = JSON.parseObject(res, PersonListResponseSg.class);

        return res;
    }

    private void setBody() {
        //设置请求参数
        Map<String, Object> map = new HashMap<>();
        map.put("pageNum", this.pageNum);
        map.put("pageSize", this.pageSize);
        map.put("isContain", this.isContain);
        map.put("searchKey", this.searchKey);
        map.put("statusList", this.statusList);
        map.put("departmentId", this.departmentId);
        this.setBody(JSON.toJSONString(map));

    }


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