package com.sckw.payment.model.constant;

import com.sckw.payment.api.model.constant.ChannelEnum;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * 交易方式 枚举 trading_type
 *
 * @author xucaiqin
 * @date 2023-07-11 12:00:52
 */
public enum TradingEnum {
    PRE_PAY(1, "1", "预付款"),
//    PRE_PAY_HF(11, PRE_PAY.value + ChannelEnum.HF.getValue(), "预付款-汇付"),
//    PRE_PAY_XS(12, PRE_PAY.value + ChannelEnum.XS.getValue(), "预付款-新生"),
//    PRE_PAY_ZX(13, PRE_PAY.value + ChannelEnum.ZX.getValue(), "预付款-中信"),
    PRE_PAY_XW(14, PRE_PAY.value + ChannelEnum.XW.getValue(), "预付款-新网"),
    RECEIVE_PAY(2, "2", "货到付款"),
//    RECEIVE_PAY_HF(21, RECEIVE_PAY.value + ChannelEnum.HF.getValue(), "货到付款-汇付"),
//    RECEIVE_PAY_XS(22, RECEIVE_PAY.value + ChannelEnum.XS.getValue(), "货到付款-新生"),
//    RECEIVE_PAY_ZX(23, RECEIVE_PAY.value + ChannelEnum.ZX.getValue(), "货到付款-中信"),
    RECEIVE_PAY_XW(24, RECEIVE_PAY.value + ChannelEnum.XW.getValue(), "货到付款-新网"),
    OFFLINE_PAY(3, "3", "线下付款");

    private final int status;
    private final String value;
    private final String desc;

    TradingEnum(int status, String value, String desc) {
        this.status = status;
        this.value = value;
        this.desc = desc;
    }

    public static String getDesc(Integer status) {
        if (Objects.isNull(status)) {
            return "";
        }
        for (TradingEnum value : values()) {
            if (status == value.getStatus()) {
                return value.getDesc();
            }
        }
        return "";
    }

    //根据支付方式获取交易方式前缀
    public static Integer getPrefix(String trading) {
        if (StringUtils.isNotBlank(trading)) {
            for (TradingEnum value : values()) {
                if (StringUtils.equals(value.getValue(), trading.substring(0, 1))) {
                    return value.getStatus();
                }
            }
        }
        return null;
    }

    public int getStatus() {
        return status;
    }


    public String getDesc() {
        return desc;
    }

    public String getValue() {
        return value;
    }


}
