package com.sckw.payment.api.model.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

@Getter
@AllArgsConstructor
public enum ChannelEnum {
//    HF("11", "1", "huifu", "汇付渠道"),
//    XS("12", "2", "newpay", "新生渠道"),
//    ZX("13", "3", "citic", "中信渠道"),
    XW("14", "4", "xinwang", "新网银行"),
    ;

    /**
     * 预付款+支付渠道
     */
    private final String code;

    /**
     * 渠道对应的字典值
     */
    private final String value;
    private final String channel;
    private final String desc;

    /**
     * 通过交易方式获取支付渠道
     *
     * @param trading 交易方式字典
     * @return
     */
    public static ChannelEnum getByTrading(String trading) {
        //长度为1 表示线下付款
        if (StringUtils.isBlank(trading) || trading.length() <= 1) {
            return null;
        }
        String channel = trading.substring(1, 2);
        for (ChannelEnum channelEnum : ChannelEnum.values()) {
            if (channelEnum.getValue().equals(channel)) {
                return channelEnum;
            }
        }
        return null;
    }

    public static ChannelEnum getByCode(String code) {
        for (ChannelEnum channelEnum : ChannelEnum.values()) {
            if (channelEnum.getCode().equals(code)) {
                return channelEnum;
            }
        }
        return null;
    }

    /**
     * 通过渠道获取
     *
     * @param channel 渠道
     * @return
     */
    public static ChannelEnum getByChannel(String channel) {
        for (ChannelEnum channelEnum : ChannelEnum.values()) {
            if (channelEnum.getChannel().equals(channel)) {
                return channelEnum;
            }
        }
        return null;
    }

    /**
     * 通过渠道获取描述
     *
     * @param channel 渠道
     * @return 渠道名称
     */
    public static String getDesc(String channel) {
        for (ChannelEnum channelEnum : ChannelEnum.values()) {
            if (channelEnum.getChannel().equals(channel)) {
                return channelEnum.getDesc();
            }
        }
        return "";
    }

    /**
     * 通过渠道获取字典值
     *
     * @param channel
     * @return
     */
    public static String getDict(String channel) {
        for (ChannelEnum channelEnum : ChannelEnum.values()) {
            if (channelEnum.getChannel().equals(channel)) {
                return channelEnum.getValue();
            }
        }
        return "";
    }

    /**
     * 通过字典值获取
     *
     * @param value
     * @return
     */
    public static ChannelEnum getByValue(String value) {
        for (ChannelEnum channelEnum : ChannelEnum.values()) {
            if (channelEnum.getValue().equals(value)) {
                return channelEnum;
            }
        }
        return null;
    }
}
