package com.gci.boot.modules.monitor.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

public enum DirectionEnum {

    E(45, 135, "东"),
    S(135, 225, "南"),
    W(225, 315, "西"),
    N_1(315, 360, "北"),
    N_2(0, 45, "北");

    @Getter
    private Integer min;
    @Getter
    private Integer max;
    @Getter
    private String label;

    DirectionEnum(Integer min, Integer max, String label) {
        this.min = min;
        this.max = max;
        this.label = label;
    }


    public static String get(String str) {
        int val = 0;
        if(StrUtil.isNotBlank(str)){
            try{
                val = Integer.valueOf(str);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        int finalVal = val;
        DirectionEnum directionEnum  = Arrays.stream(values())
                .filter(r -> finalVal > r.min && finalVal <= r.max)
                .findFirst()
                .orElse(null);

        if(Objects.nonNull(directionEnum)){
            return directionEnum.label;
        } else{
            return "";
        }
    }
}
