package com.wzj.soopin.transaction.enums.easypay;

import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.dromara.common.core.domain.event.Constants;
import org.dromara.common.core.exception.ServiceException;

import java.util.Arrays;

/**
 * 支付方式
 */
@Getter
@AllArgsConstructor
@Schema(description = "易生支持的支付方式")
public enum PayType {

    @Schema(description = "支付宝服务窗支付")
    ALI_PAY_JSAPI("AliPayJsapi", Constants.PayType.ALIPAY, "支付宝服务窗支付 "),

    @Schema(description = "支付宝小程序支付")
    ALI_PAY_MINI_APP("AliPayMiniApp", Constants.PayType.ALIPAY, "支付宝小程序支付"),

    @Schema(description = "微信公众号支付")
    WE_CHAT_JSAPI("WeChatJsapi", Constants.PayType.WECHAT, "微信公众号支付"),

    @Schema(description = "微信小程序支付")
    WE_CHAT_MINI_APP("WeChatMiniApp", Constants.PayType.WECHAT, "微信小程序支付"),

    @Schema(description = "云闪付JS")
    UNION_PAY_JSAPI("UnionPayJsapi", Constants.PayType.UNION, "云闪付JS"),

    @Schema(description = "云闪付JS云微")
    UNION_PAY_Js_MINI("UnionPayJsMini", Constants.PayType.UNION, "云闪付JS云微");


    /**
     * 接口中实际使用的值
     */
    private final String value;

    /**
     * 支付渠道
     */
    private final Integer channel;

    /**
     * 支付方式描述
     */
    private final String info;

    public static PayType getByValue(String value) {
        return Arrays.stream(PayType.values())
            .filter(e -> StrUtil.equals(e.getValue(), value))
            .findFirst()
            .orElseThrow(() -> new ServiceException("支付方式不存在"));

    }
}
