package com.zanxiang.game.module.base.pojo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.logging.log4j.util.Strings;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 支付设备类型
 *
 * @author xufeng
 * @date 2022/6/16 18:07
 */
@Getter
@AllArgsConstructor
public enum PayDeviceEnum {

    /**
     * Pc端支付
     */
    PC_PAY(1L, "PC", "PC二维码支付"),

    /**
     * h5支付
     */
    H5_PAY(2L, "H5", "H5支付"),

    /**
     * App支付
     */
    APP_PAY(3L, "APP", "APP支付"),

    /**
     * 小程序支付
     */
    APPLET_PAY(4L, "APPLET", "盒子支付"),

    /**
     * 米大师支付
     */
    MI_PAY(5L, "MI_PAY", "米大师支付"),

    /**
     * 客服支付
     */
    CUSTOM_PAY(6L, "CUSTOM_PAY", "客服支付"),

    /**
     * 公众号支付
     */
    MP_PAY(7L, "MP_PAY", "公众号支付");

    /**
     * 支付方式id
     */
    private final Long payDeviceId;

    /**
     * 支付方式key
     */
    private final String payDeviceKey;

    /**
     * 支付方式名称
     */
    private final String payDeviceName;

    /**
     * 根据支付方式id获取名称
     *
     * @param payDeviceId : 支付方式id
     * @return : 支付类型枚举
     */
    public static String getByPayWayId(Long payDeviceId) {
        if (payDeviceId == null) {
            return Strings.EMPTY;
        }
        PayDeviceEnum payDeviceEnum = PayDeviceEnum.getPayDeviceEnum(payDeviceId);
        return payDeviceEnum == null ? Strings.EMPTY : payDeviceEnum.getPayDeviceName();
    }

    /**
     * 得到支付设备枚举
     *
     * @param payDeviceId 支付设备id
     * @return {@link PayDeviceEnum}
     */
    public static PayDeviceEnum getPayDeviceEnum(Long payDeviceId) {
        if (payDeviceId == null) {
            return null;
        }
        for (PayDeviceEnum payDeviceEnum : PayDeviceEnum.values()) {
            if (Objects.equals(payDeviceId, payDeviceEnum.getPayDeviceId())) {
                return payDeviceEnum;
            }
        }
        return null;
    }

    /**
     * 获取特殊的支付类型(预下单在获取支付参数)
     *
     * @return {@link List}<{@link Long}>
     */
    public static List<Long> getByPayWayIdList() {
        return Arrays.asList(PayDeviceEnum.APPLET_PAY.getPayDeviceId(),
                PayDeviceEnum.CUSTOM_PAY.getPayDeviceId(),
                PayDeviceEnum.MP_PAY.getPayDeviceId());
    }
}
