package com.sckw.product.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

/**
 * @desc: 产品状态枚举
 * @author: yzc
 * @date: 2023-07-06 13:53
 */
@AllArgsConstructor
@Getter
public enum GoodsStatusEnum {

    /**
     * 产品状态枚举
     */
    SAVED(0, "已保存"),
    PUT_ON_SHELVES(1, "上架中"),
    TAKE_OFF_SHELVES(2, "已下架");

    private Integer code;
    private String msg;


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

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

}
