package com.sckw.goods.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;

/**
 * @desc:
 * @author: Lt
 * @date: 2024-04-29
 */
@AllArgsConstructor
@Getter
public enum GoodsStatusEnums {
    ONE(1, "已保存"),
    TWO(2, "已上架"),
    THREE(3, "已下架"),
    FOUR(4, "已售罄"),
    FIVE(5, "审核中")
    ;

    private final Integer code;
    private final String msg;


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

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