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.Map;

@Data
public class ClientCarAddRequestHn extends BaseRequest02<Object> {


    /*车牌号码*/
    private String carNum;

    /*车辆编号*/
    private String carCode;

    /*汽车颜色*/
    private String carColor;

    /*车牌颜色*/
    private String carNumColor;

    /*车辆类型*/
    private String carType;

    /*黑白名单*/
    private Integer listType;

    /*人员id*/
    private Long ownerId;

    /*停车类型*/
    private Integer parkType;

    /*绑定场区编号*/
    private String parkinglotCode;

    /*车辆品牌*/
    private String carBrand;

    /*部门Id*/
    private String deptId;

    /*部门名称*/
    private String deptName;


    public ClientCarAddRequestHn() {
    }

    public ClientCarAddRequestHn(OauthConfigBaseInfo02 oauthConfigBaseInfo) {
        super(oauthConfigBaseInfo, Constant.HTTP_POST, oauthConfigBaseInfo.getHttpConfigInfo().getPrefixUrl() + Constant.CAR_LIST_ADD, true);
    }

    @Override
    public Object 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 res;
    }

    private void setBody() {
        //设置请求参数
        Map<String, Object> map = new HashMap<>();
        map.put("carNum", this.carNum);
        map.put("carCode", this.carCode);
        map.put("carColor", this.carColor);
        map.put("carNumColor", this.carNumColor);
        map.put("carType", this.carType);
        map.put("listType", this.listType);
        map.put("ownerId", this.ownerId);
        map.put("parkType", this.parkType);
        map.put("parkinglotCode", this.parkinglotCode);
        map.put("carBrand", this.carBrand);
        map.put("deptId", this.deptId);
        map.put("deptName", this.deptName);
//        map.put("method", this.method);
//        map.put("data", this.data);
        this.setBody(JSON.toJSONString(map));

    }


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