package com.haha.common.enums;

import lombok.Getter;

/**
 * 支付渠道枚举
 */
@Getter
public enum PaymentChannel {

    WECHAT("wechat", "微信支付"),
    ALIPAY("alipay", "支付宝支付"),
    ALIPAY_CREDIT("alipay_credit", "支付宝信用支付"),
    BALANCE("balance", "余额支付"),
    WECHAT_PAYSCORE("wechat_payscore", "微信支付分");

    private final String code;
    private final String description;

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

    /**
     * 根据code获取对应的枚举值
     * @param code 支付渠道编码
     * @return 对应的枚举值，未匹配返回null
     */
    public static PaymentChannel fromCode(String code) {
        if (code == null) {
            return null;
        }
        for (PaymentChannel channel : values()) {
            if (channel.code.equals(code)) {
                return channel;
            }
        }
        return null;
    }

    /**
     * 判断code是否有效
     * @param code 支付渠道编码
     * @return 是否有效
     */
    public static boolean isValid(String code) {
        return fromCode(code) != null;
    }
}
