package com.sckw.order.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: yzc
 * @date: 2023-07-06 13:53
 */
@AllArgsConstructor
@Getter
public enum WantBuyStatusEnum {

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

    private final Integer code;
    private final String msg;


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

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

}
