package com.multictrl.common.utils.weather;

/**
 * 雨量工具类
 *
 * @author Sdy
 * @since 1.0.0 2025/10/13
 */
public class RainfallUtils {

    // 小雨类天气现象
    public static final String[] LIGHT_RAIN_TYPES = {
            "毛毛雨/细雨",
            "小雨",
            "阵雨",
            "雷阵雨",
            "雨雪天气",
            "雨夹雪",
            "阵雨夹雪",
            "冻雨"
    };

    // 中雨类天气现象
    public static final String[] MODERATE_RAIN_TYPES = {
            "中雨",
            "小雨-中雨",
            "雷阵雨并伴有冰雹"
    };

    // 大雨类天气现象
    public static final String[] HEAVY_RAIN_TYPES = {
            "大雨",
            "中雨-大雨",
            "强阵雨",
            "强雷阵雨",
            "暴雨",
            "大暴雨",
            "特大暴雨",
            "极端降雨",
            "大雨-暴雨",
            "暴雨-大暴雨",
            "大暴雨-特大暴雨"
    };

    /**
     * 判断是否为小雨类
     */
    public static boolean isMinRain(String precipitation) {
        return contains(LIGHT_RAIN_TYPES, precipitation);
    }

    /**
     * 判断是否为中雨类
     */
    public static boolean isModerateRain(String precipitation) {
        return contains(MODERATE_RAIN_TYPES, precipitation);
    }

    /**
     * 判断是否为大雨类
     */
    public static boolean isMaxRain(String precipitation) {
        return contains(HEAVY_RAIN_TYPES, precipitation);
    }

    /**
     * 获取降水类型所属的类别名称
     */
    public static String getCategory(String precipitation) {
        if (isMinRain(precipitation)) return "小雨";
        if (isModerateRain(precipitation)) return "中雨";
        if (isMaxRain(precipitation)) return "大雨";
        return "未知";
    }

    /**
     * 检查字符串是否在数组中
     */
    private static boolean contains(String[] array, String value) {
        for (String item : array) {
            if (item.equals(value)) {
                return true;
            }
        }
        return false;
    }
}
