package com.sckw.mine.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@AllArgsConstructor
@Getter
public enum NodeTypeEnum {
    ONE(1, "节点类型1"),
    TWO(2, "节点类型2")
    ;

    private final Integer code;
    private final String msg;


    public static String getNameByCode(Integer code) {
        NodeTypeEnum[] enums = NodeTypeEnum.values();
        for (NodeTypeEnum instance : enums) {
            if (Objects.equals(instance.getCode(), code)) {
                return instance.getMsg();
            }
        }
        return null;
    }

    public static List<NodeTypeEnum> getSortList() {
        NodeTypeEnum[] enums = NodeTypeEnum.values();
        return Arrays.stream(enums).sorted(Comparator.comparingInt(NodeTypeEnum::getCode)).collect(Collectors.toList());
    }
}
