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 FileUploadBizEnum implements BaseEnum {

    AVATAR("用户头像", "avatar"),
    PROJECT("项目", "project"),
    RICH_TEXT("富文本", "richText"),
    DEFAULT("默认", "default");

    private final String text;
    private final String value;

    FileUploadBizEnum(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 FileUploadBizEnum getEnumByValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (FileUploadBizEnum anEnum : FileUploadBizEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }
}

