package com.drops.exp.util;

import cn.hutool.http.HttpResponse;
import com.drops.utils.HTTPUtils;
import com.drops.utils.ResponseUtil;
import com.drops.utils.URLUtil;

/**
 * @ClassName: EnvPost
 * @Description: TODO
 * @Author: Summer
 * @Date: 2021/7/29 11:10
 * @Version: v1.0.0
 * @Description:
 **/
public class EnvPost {

    /**
     * @Description: env
     * @param target
     * @param boby
     *
     * @return:
     */
    public static Boolean PostEnv(String target, String boby){
        if (isPostEnv(target)) {
            HttpResponse result = HTTPUtils.postRequestV1(target, "env", boby);
            if (ResponseUtil.getStats(result) == 200) {
                if (ResponseUtil.getBoby(result).isEmpty()) {
                    System.out.println("返回包状态码 200,但返回包内容为null！请手工验证是否成功！");
                    return true;
                }
                return true;
            } else {
                System.out.println("返回包状态码：" + ResponseUtil.getStats(result));
                System.out.println(boby + " 属性设置失败！");
            }
        }
        return true;
    }

    public static Boolean PostEnvV2(String target, String boby){
        if (isPostEnv(target)) {
            HttpResponse result = HTTPUtils.postRequestV2(target, "actuator/env", boby);
            if (ResponseUtil.getStats(result) == 200) {
                if (ResponseUtil.getBoby(result).isEmpty()) {
                    System.out.println("返回包状态码 200,但返回包内容为null！请手工验证是否成功！");
                    return true;
                }
                return true;
            } else {
                System.out.println("返回包状态码：" + ResponseUtil.getStats(result));
                System.out.println(boby + " 属性设置失败！");
            }
        }
        return true;
    }

    /**
     * @Description: 验证env端口是否存活，能否接受post请求
     * @param target
     *
     * @return:
     */
    public static boolean isPostEnv(String target){
//        HttpResponse result = HTTPUtils.postRequestV1(target,"env");
//        if (!ResponseUtil.getBoby(result).isEmpty()){
//            return true;
//        }
        return true;
    }

    public static boolean isPostEnvV2(String target){
//        HttpResponse result = HTTPUtils.postRequestV2(target,"actuator/env");
//        if (ResponseUtil.getStats(result) == 200){
//            return true;
//        }
        return true;
    }

}
