package com.seer.teach.common.enums.pay;

/**
 * 支付状态枚举类
 */
public enum PayStatusEnum {

    PENDING(0, "NOTPAY","待支付"),
    SUCCESS(1, "SUCCESS","支付成功"),
    PAY_FAILED(2, "PAYERROR","支付失败"),
    APPLY_REFUND(3, "","申请退款"),
    CANCEL(4, "","取消支付"),
    PENDING_REVIEW(20, "","审核中"),
    REVIEW_APPROVED(21, "","审核通过，待微信退款"),
    REVIEW_REJECTED(22, "","审核拒绝"),

    WECHAT_REFUND_PROCESSING(31, "PROCESSING","微信退款处理中"),
    WECHAT_REFUND_SUCCESS(32, "SUCCESS","微信退款成功"),
    WECHAT_REFUND_CLOSED(33 ,"CLOSED","微信退款关闭"),
    WECHAT_REFUND_FAILED(34, "ABNORMAL","微信退款失败，人工处理");

    private final int code;

    private final String wechatNotifyStatus;
    private final String description;

    PayStatusEnum(int code, String wechatNotifyStatus,String description) {
        this.code = code;
        this.wechatNotifyStatus = wechatNotifyStatus;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public String getWechatNotifyStatus() {
        return wechatNotifyStatus;
    }

    /**
     * 根据code获取对应的枚举值
     * @param wxStatus 状态码
     * @return 对应的枚举，如果不存在则返回null
     */
    public static PayStatusEnum fromWxOrderCode(String wxStatus) {
        for (PayStatusEnum status : PayStatusEnum.values()) {
            if (status.getWechatNotifyStatus().equalsIgnoreCase(wxStatus)) {
                return status;
            }
        }
        return null;
    }
}
