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

    CLOSED("交易关闭"),
    SUCCESS("交易成功"),
    PENDING("待支付"),
    REFUNDED("已退款");

    private final String value;

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

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

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

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