package com.ruoyi.ss.account.domain.enums;

import com.ruoyi.common.constants.ChannelConstants;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 账户类型
 * @author wjh
 * 2024/3/26
 */
@AllArgsConstructor
@Getter
public enum AccountType {

    BANK_CARD("1", "个人银行卡", ChannelConstants.BANK_CARD_ID),
    WECHAT("2", "微信", ChannelConstants.WECHAT_ID),
    ALIPAY("3", "支付宝", ChannelConstants.ALIPAY_ID),
    OFFLINE_IMAGE("4", "线下图片", ChannelConstants.QR_CODE_ID);


    private final String type;  // 类型
    private final String name;  // 名称
    private final Long channelId;   // 渠道id

    public static AccountType parse(String type) {
        for (AccountType obj : AccountType.values()) {
            if (Objects.equals(obj.getType(), type)) {
                return obj;
            }
        }
        return null;
    }

    public static AccountType parseByChannel(Long channelId) {
        if (channelId == null) {
            return null;
        }
        for (AccountType obj : AccountType.values()) {
            if (Objects.equals(obj.getChannelId(), channelId)) {
                return obj;
            }
        }
        return null;
    }
}
