package com.haha.common.enums;

import lombok.Getter;

@Getter
public enum PayStatus {

    UNPAID("UNPAID", "未支付"),
    PAID("PAID", "已支付"),
    PARTIAL_REFUND("PARTIAL_REFUND", "部分退款"),
    REFUND("REFUND", "全额退款");

    private final String code;
    private final String description;

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

    public static PayStatus fromCode(String code) {
        if (code == null) {
            return null;
        }
        for (PayStatus status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        return null;
    }

    public static String getDescription(String code) {
        PayStatus status = fromCode(code);
        return status != null ? status.description : "未知";
    }

    public static boolean isUnpaid(String code) {
        return UNPAID.code.equals(code);
    }

    /** 已支付或部分退款均视为已付款状态 */
    public static boolean isPaid(String code) {
        return PAID.code.equals(code) || PARTIAL_REFUND.code.equals(code);
    }

    public static boolean isRefund(String code) {
        return REFUND.code.equals(code);
    }
}
