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

    PROCESSING("提现中", "processing"),
    SUCCESS("提现成功", "success"),
    FAILED("提现失败", "failed");

    private final String text;

    private final String value;

    WithdrawStatusEnum(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(WithdrawStatusEnum::getValue)
                .collect(Collectors.toList());
    }

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

}
