package com.sckw.usual.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 GoodsUnitEnum {
    ONE(1, "%"),
    TWO(2, "t"),
    THREE(3, "m3");

    private final Integer code;
    private final String msg;


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

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