package com.common.lib_base.utils;

import android.text.TextUtils;

import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

/**
 * Date: 2022/5/24 0024 16:40
 * Description:
 */
public final class StringUtils {

    public static boolean isNullAndZero(String str) {
        return str == null || TextUtils.isEmpty(str) || "".equals(str) || "null".equals(str) || "0".equals(str) || "0.00".equals(str) || "0.0".equals(str);
    }

    public static boolean isNull(String str) {
        return str == null || TextUtils.isEmpty(str) || "".equals(str) || "null".equals(str) || str.length() <= 0;
    }

    public static boolean isNotNull(String str) {
        return str != null && !TextUtils.isEmpty(str) && !"".equals(str) && !"null".equals(str) && str.length() > 0;
    }

    public static boolean isNotNullAndZero(String str) {
        return str != null && !TextUtils.isEmpty(str) && !"".equals(str) && !"null".equals(str) && str.length() > 0 && !"0".equals(str);
    }


    public static boolean isBig(String str1, String str2) {
        BigDecimal bd1 = new BigDecimal(str1);
        BigDecimal bd2 = new BigDecimal(str2);
        int i = bd1.compareTo(bd2);
        LogUtils.e("StringUtils--isMoneyValid:" + i);
        //返回的结果是int类型，-1表示小于，0是等于，1是大于
        if (i == 1 || i == 0) {
            return true;
        } else {
            return false;
        }
    }


    /**
     * 将1.0截取小数点前数字
     *
     * @param i 1.0
     * @return 1
     */
    public static String format(float i) {
        String[] v = (i + "").split(".");
        return v[0];
    }


    /**
     * @param text
     * @return String 返回类型
     * @Title: fmtMicrometer
     * @Description: 格式化数字为千分位
     */
    public static String fmtMicrometer(String text) {

        DecimalFormat df = null;

        if (text.indexOf(".") > 0) {

            if (text.length() - text.indexOf(".") - 1 == 0) {

                df = new DecimalFormat("###,##0.");

            } else if (text.length() - text.indexOf(".") - 1 == 1) {

                df = new DecimalFormat("###,##0.0");

            } else {

                df = new DecimalFormat("###,##0.00");

            }

        } else {

            df = new DecimalFormat("###,##0");

        }

        double number = 0.0;

        try {

            number = Double.parseDouble(text);

        } catch (Exception e) {

            number = 0.0;

        }

        return df.format(number);

    }


    /**
     * 将-转为.
     *
     * @param str
     * @return
     */
    public static String replaceLineToPoint(String str) {
        if (isNull(str)) {
            return "";
        }
        String replaceStr = str.replace("-", ".");
        return replaceStr;
    }

    /**
     * 将-转为.
     *
     * @param str
     * @return
     */
    public static String replaceLineToBlank(String str) {
        if (isNull(str)) {
            return "";
        }
        String replaceStr = str.replace("-", "");
        return replaceStr;
    }


    /**
     * 隐藏手机号中间四位
     *
     * @param str
     * @return
     */
    public static String handlePhone(String str) {
        if (isNull(str)) {
            return "";
        }
        String resultPhone;
        if (str.length() == 11) {
            resultPhone = str.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
            return resultPhone;
        } else {
            resultPhone = "";
            return resultPhone;
        }

    }


    // json转String
//    String s = gson.toJson(resultData);

    // String转json
//    ProjectInfoDetailResultBean projectInfoDetailResultBean = gson.fromJson(s, ProjectInfoDetailResultBean.class);

    // 字符串转list
//    Type type = new TypeToken<List<TeamIntroResultBean.TeamEquipmentsBean>>() {}.getType();
//    List<TeamIntroResultBean.TeamEquipmentsBean> teamEquipments = gson.fromJson(equipmentsTreeStr, type);

}
