package com.greenorange.promotion.model.enums;

import com.greenorange.promotion.annotation.BaseEnum;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 项目状态枚举
 */
@Getter
public enum ProjectStatusEnum implements BaseEnum {

    RUNNING("项目运行", "running"),
    FULL("人数已满", "full"),
    PAUSED("项目暂停", "paused");

    private final String text;
    private final String value;

    ProjectStatusEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * BaseEnum 要求的方法：返回这个枚举的“校验值”
     */
    @Override
    public String getValue() {
        return this.value;
    }

    /**
     * 获取值列表
     */
    public static List<String> getValues() {
        return Arrays.stream(values())
                .map(item -> item.value)
                .collect(Collectors.toList());
    }

    /**
     * 根据值获取枚举
     */
    public static ProjectStatusEnum getEnumByValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (ProjectStatusEnum status : ProjectStatusEnum.values()) {
            if (status.value.equals(value)) {
                return status;
            }
        }
        return null;
    }
}
