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

import com.alibaba.fastjson.JSON;
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.utils.HttpURLConnectionUtil;
import com.huimv.video.dhicc.test.utils.HttpsURLConnectionUtil;
import com.huimv.video.dhicc.test.utils.UrlUtil;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class ClientCarWhiteAddRequestCn extends BaseRequest03<Object> {



    private List<Object> a;






    public ClientCarWhiteAddRequestCn() {
    }

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

        return res;
    }

    private void setBody() {
        //设置请求参数
        /*Map<String, Object> map = new HashMap<>();
        map.put("a", a);*/
        List<Object> map = new ArrayList<>();
        map = this.a;
        this.setBody(JSON.toJSONString(map));

    }


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