package com.jeesharp.business.modules.finance.paymentrecord.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 支付方式/产品类型编码（存库为字符串，便于扩展三方产品码）。
 *
 * @author jeesharp
 * @since 2026-05-09
 */
@Getter
@AllArgsConstructor
public enum PayRecordPayTypeEnum {

    WECHAT_MINI("WECHAT_MINI", "微信小程序支付"),
    WECHAT_JSAPI("WECHAT_JSAPI", "微信 JSAPI"),
    WECHAT_APP("WECHAT_APP", "微信 APP 支付"),
    WECHAT_NATIVE("WECHAT_NATIVE", "微信 Native"),
    ALIPAY_APP("ALIPAY_APP", "支付宝 APP"),
    ALIPAY_WAP("ALIPAY_WAP", "支付宝手机网站"),
    ALIPAY_PC("ALIPAY_PC", "支付宝电脑网站"),
    UNION_PAY("UNION_PAY", "银联"),
    BALANCE("BALANCE", "余额支付"),
    OFFLINE("OFFLINE", "线下对公/其它");

    private final String code;
    private final String desc;

    public static PayRecordPayTypeEnum fromCode(String code) {
        if (code == null || code.isEmpty()) {
            return null;
        }
        for (PayRecordPayTypeEnum e : values()) {
            if (e.code.equals(code)) {
                return e;
            }
        }
        return null;
    }

    public static String getDescByCode(String code) {
        PayRecordPayTypeEnum e = fromCode(code);
        return e != null ? e.getDesc() : (code == null ? "" : code);
    }
}
