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 GoodsTypeEnum {
    ONE(1, "清货"),
    TWO(2, "重货");

    private final Integer code;
    private final String msg;


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

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