package com.jeesharp.business.modules.pay.paychannelconfig.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 支付渠道编码，与 {@link com.jeesharp.business.modules.pay.enums.PayTypeStyle} 对应。
 *
 * @author jeesharp
 * @since 2026-05-25
 */
@Getter
@AllArgsConstructor
public enum PayChannelCodeEnum {

    WECHAT("WECHAT", "微信", "1"),
    ALIPAY("ALIPAY", "支付宝", "2"),
    PFA("PFA", "浦发", "3"),
    TLINX("TLINX", "TLinx", "4");

    private final String code;
    private final String desc;
    /** 对应 PayTypeStyle.value */
    private final String payTypeValue;

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

    public static PayChannelCodeEnum fromPayTypeValue(String payTypeValue) {
        if (payTypeValue == null || payTypeValue.isEmpty()) {
            return null;
        }
        for (PayChannelCodeEnum e : values()) {
            if (e.payTypeValue.equals(payTypeValue)) {
                return e;
            }
        }
        return null;
    }

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