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

/**
 * 退款状态枚举类
 */
public enum RefundStatusEnum {

    PENDING_REVIEW(0, "待审核"),
    REVIEW_APPROVED(1, "审核通过"),
    REVIEW_REJECTED(2, "审核拒绝"),
    PENDING_WECHAT_REFUND(3, "待退款"),
    REFUND_SUCCESS(4, "退款成功"),
    WECHAT_REFUND_PROCESSING(5, "退款处理中"),
    WECHAT_REFUND_CLOSED(6, "退款关闭"),
    WECHAT_REFUND_FAILED(7, "退款失败");

    private final int code;
    private final String description;

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

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据code获取对应的枚举值
     *
     * @param code 状态码
     * @return 枚举对象
     */
    public static RefundStatusEnum fromCode(int code) {
        for (RefundStatusEnum status : RefundStatusEnum.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid refund status code: " + code);
    }


    /**
     * 解析微信的退款状态
     *
     * @param status 状态码
     * @return 枚举对象
     */
    public static RefundStatusEnum fromWxCode(String status) {

        if("SUCCESS".equalsIgnoreCase( status)){
            return REFUND_SUCCESS;
        }
        if("PROCESSING".equalsIgnoreCase( status)){
            return WECHAT_REFUND_PROCESSING;
        }
        if("CLOSED".equalsIgnoreCase( status)){
            return WECHAT_REFUND_CLOSED;
        }
        if("ABNORMAL".equalsIgnoreCase( status)){
            return WECHAT_REFUND_FAILED;
        }
        throw new IllegalArgumentException("Invalid refund status code: " + status);
    }
}

