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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo02;
import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo03;
import com.huimv.video.dhicc.test.constant.Constant;
import com.huimv.video.dhicc.test.request.BaseRequest03;
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 ClientPersonAddRequestCn extends BaseRequest03<JSONObject> {



    private Integer pagerType;
    private Integer code;
    private Integer departmentId;
    private String name;
    private String paperNumber;
    private Integer phone;
    private Integer id;


    public ClientPersonAddRequestCn() {
    }

    public ClientPersonAddRequestCn(OauthConfigBaseInfo03 oauthConfigBaseInfo) {
        super(oauthConfigBaseInfo, Constant.HTTP_POST, oauthConfigBaseInfo.getHttpConfigInfo().getPrefixUrl() + Constant.CAR_PERSON_ADD, true);
    }

    @Override
    public JSONObject 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());
        System.out.println(res);
        //获取响应
        JSONObject jsonObject = JSONObject.parseObject(res);
//        Object data = jsonObject.get("data");
//        GeneralResponse devicePageResponse = JSON.parseObject(res, GeneralResponse.class);
//        System.out.println(data);
        return jsonObject;
    }

    private void setBody() {
        //设置请求参数
        Map<String, Object> map = new HashMap<>();
        map.put("pagerType", this.pagerType);
        map.put("code", this.code);
        map.put("departmentId", this.departmentId);
        map.put("name", this.name);
        map.put("paperNumber", this.paperNumber);
        map.put("phone", this.phone);
        map.put("id", this.id);
        this.setBody(JSON.toJSONString(map));

    }


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