package com.wzj.soopin.transaction.enums.easypay;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.dromara.common.core.exception.ServiceException;

import java.util.Arrays;


/**
 * 分账单状态，（处理中、成功、失败、已退款）
 */
@Getter
@AllArgsConstructor
public enum SepaStatus {

    SUCCESS("0", "成功"),
    FAIL("FAIL", "失败"),
    PENDING("PENDING", "处理中"),
    PROCESSING("PROCESSING", "处理中"),
    REFUNDED("REFUNDED", "已退款");


    /**
     * 状态code
     */
    private final String value;

    /**
     * 状态描述
     */
    private final String info;

    public static SepaStatus getByValue(String value) {
        return Arrays.stream(SepaStatus.values())
            .filter(e -> StrUtil.equals(e.getValue(), value))
            .findFirst()
            .orElseThrow(() -> new ServiceException("分账状态不存在"));

    }
}
