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

    PENDING("待提成"),
    COMPLETED("已提成"),
    EXPIRED("已失效");

    private final String value;

    CommissionStatusEnum(String value) {
        this.value = value;
    }

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

    /**
     * 获取所有枚举值列表
     */
    public static List<String> getValues() {
        return Arrays.stream(values())
                     .map(CommissionStatusEnum::getValue)
                     .collect(Collectors.toList());
    }

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