
package com.tmerclub.cloud.common.constant;

import java.util.Objects;

/**
 * @author tmerclub
 */
public enum PayType {
    /**
     * 未支付
     */
    UNPAY(-1, "未支付", ""),

    /**
     * 积分支付
     */
    SCOREPAY(0, "积分支付", ""),

    /**
     * 微信小程序支付，通联为[微信小程序支付_集团（收银宝）]
     */
    WECHATPAY(1, "微信小程序支付", "WECHATPAY_MINIPROGRAM_ORG"),

    /**
     * 支付宝，电脑网站支付，通联为[支付宝扫码支付(正扫) _集团]
     */
    ALIPAY(2, "支付宝", "SCAN_ALIPAY_ORG"),

    /**
     * 微信扫码支付，通联为[微信扫码支付(正扫) _集团——收银宝]
     */
    WECHATPAY_SWEEP_CODE(3, "微信扫码支付", "SCAN_WEIXIN_ORG"),

    /**
     * 微信H5支付，通联在此处[收银宝H5收银台_集团]
     */
    WECHATPAY_H5(4, "微信H5支付", "H5_CASHIER_VSP_ORG"),

    /**
     * 微信公众号，通联为[微信JS支付（公众号）_集团——收银宝]
     */
    WECHATPAY_MP(5, "微信公众号支付", "WECHAT_PUBLIC_ORG"),

    /**
     * 支付宝H5支付，手机网站支付，通联为[收银宝H5收银台_集团]
     */
    ALIPAY_H5(6, "支付宝H5支付", "H5_CASHIER_VSP_ORG"),

    /**
     * 支付宝APP支付，通联为[收银宝支付宝APP支付_集团]，通联此支付方式无法使用
     */
    ALIPAY_APP(7, "支付宝APP支付", "ALIPAY_APP_VSP_ORG"),

    /**
     * 微信APP支付，通联为[微信原生APP支付]
     */
    WECHATPAY_APP(8, "微信APP支付", "WECHATPAY_APP_OPEN"),

    /**
     * 余额支付，通联为[账户余额]
     */
    BALANCE(9, "余额支付", "BALANCE"),

    /**
     * 商家余额支付
     */
    SHOP_BALANCE(10, "商家余额支付", "SHOP_BALANCE"),

    /**
     * 平台余额支付
     */
    PLATFORM_BALANCE(11, "平台余额支付", "PLATFORM_BALANCE");


    private final Integer num;

    private final String payTypeName;
    private final String allinpayCode;

    public Integer value() {
        return num;
    }

    public String getPayTypeName() {
        return payTypeName;
    }

    public String getAllinpayCode() {
        return allinpayCode;
    }

    public static final Integer[] WE_CHAT_PAY_ARRAY = {WECHATPAY.value(), WECHATPAY_APP.value(), WECHATPAY_H5.value(), WECHATPAY_MP.value(), WECHATPAY_SWEEP_CODE.value()};
    public static final Integer[] ALI_PAY_ARRAY = {ALIPAY.value(), ALIPAY_H5.value(), ALIPAY_APP.value()};

    PayType(Integer num, String payTypeName, String allinpayCode) {
        this.num = num;
        this.payTypeName = payTypeName;
        this.allinpayCode = allinpayCode;
    }

    public static PayType instance(Integer value) {
        PayType[] enums = values();
        for (PayType statusEnum : enums) {
            if (statusEnum.value().equals(value)) {
                return statusEnum;
            }
        }
        return null;
    }

    public static String getPayTypeName(Integer value) {
        PayType[] enums = values();
        for (PayType statusEnum : enums) {
            if (statusEnum.value().equals(value)) {
                return statusEnum.payTypeName;
            }
        }
        return null;
    }

    public static Boolean isWeChatPay(Integer value) {
        return Objects.equals(value, WECHATPAY.value()) || Objects.equals(value, WECHATPAY_APP.value()) ||
                Objects.equals(value, WECHATPAY_H5.value()) || Objects.equals(value, WECHATPAY_MP.value()) ||
                Objects.equals(value, WECHATPAY_SWEEP_CODE.value());
    }

    public static Boolean isAliPay(Integer value) {
        return Objects.equals(value, ALIPAY.value()) || Objects.equals(value, ALIPAY_H5.value()) ||
                Objects.equals(value, ALIPAY_APP.value());
    }
}
