package com.ycwl.basic.constant;

import com.wechat.pay.java.service.payments.model.Transaction;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>@description: 微信常量  </p>
 * <p>@author: songmingsong </p>
 **/
public class WeiXinConstant {

    private static final Map<Transaction.TradeStateEnum, String> STATE_DESCRIPTION_MAP = new HashMap<>();

    static {
        STATE_DESCRIPTION_MAP.put(com.wechat.pay.java.service.payments.model.Transaction.TradeStateEnum.SUCCESS, "SUCCESS");
        STATE_DESCRIPTION_MAP.put(com.wechat.pay.java.service.payments.model.Transaction.TradeStateEnum.REFUND, "REFUND");
        STATE_DESCRIPTION_MAP.put(com.wechat.pay.java.service.payments.model.Transaction.TradeStateEnum.NOTPAY, "NOTPAY");
        STATE_DESCRIPTION_MAP.put(com.wechat.pay.java.service.payments.model.Transaction.TradeStateEnum.CLOSED, "CLOSED");
        STATE_DESCRIPTION_MAP.put(com.wechat.pay.java.service.payments.model.Transaction.TradeStateEnum.REVOKED, "REVOKED");
        STATE_DESCRIPTION_MAP.put(com.wechat.pay.java.service.payments.model.Transaction.TradeStateEnum.USERPAYING, "USERPAYING");
        STATE_DESCRIPTION_MAP.put(com.wechat.pay.java.service.payments.model.Transaction.TradeStateEnum.PAYERROR, "PAYERROR");
        STATE_DESCRIPTION_MAP.put(com.wechat.pay.java.service.payments.model.Transaction.TradeStateEnum.ACCEPT, "ACCEPT");
    }

    public static String getDescriptionState(com.wechat.pay.java.service.payments.model.Transaction.TradeStateEnum state) {
        return STATE_DESCRIPTION_MAP.getOrDefault(state, "未知状态");
    }

    private static final Map<com.wechat.pay.java.service.payments.model.Transaction.TradeTypeEnum, String> STATE_DESCRIPTION_MAP_TYPE = new HashMap<>();

    static {
        STATE_DESCRIPTION_MAP_TYPE.put(Transaction.TradeTypeEnum.JSAPI, "JSAPI");
        STATE_DESCRIPTION_MAP_TYPE.put(Transaction.TradeTypeEnum.NATIVE, "NATIVE");
        STATE_DESCRIPTION_MAP_TYPE.put(Transaction.TradeTypeEnum.APP, "APP");
        STATE_DESCRIPTION_MAP_TYPE.put(Transaction.TradeTypeEnum.MICROPAY, "MICROPAY");
        STATE_DESCRIPTION_MAP_TYPE.put(Transaction.TradeTypeEnum.MWEB, "MWEB");
        STATE_DESCRIPTION_MAP_TYPE.put(Transaction.TradeTypeEnum.FACEPAY, "FACEPAY");
    }

    public static String getDescriptionType(Transaction.TradeTypeEnum type) {
        return STATE_DESCRIPTION_MAP_TYPE.getOrDefault(type, "未知类型");
    }


    /**
     * 公众号模板地址
     */
    public static final String PUBLIC_ACCOUNT_TEMPLATE =
            "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
    /**
     * 获取微信用户基本信息地址
     */
    public static final String WECHAT_OAUTH_ACCESS_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token";
    /**
     * 获取ACCESS_TOKEN
     */
    public static final String ACCESS_TOKEN = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
    /**
     * 登录凭证校验
     */
    public static final String GET_OPEN_ID = "https://api.weixin.qq.com/sns/jscode2session";
    /**
     * 获取小程序地址
     */
    public static final String GET_MINI_QRCODE = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s";
    /**
     * 获取用户基本信息
     */
    public static final String GET_USER_BASIC_INFO = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN";
    /**
     * 获取包含请求参数ACCESS_TOKEN
     */
    public static final String ACCESS_TOKEN_WITH_PARAM = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
    /**
     * 获取小程序 URL Link
     */
    public static final String GENERATE_URL_LINK = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s";

    /**
     * 发送模板消息
     */
    public static final String MESSAGE_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=";

    /*-----------------------------*/
    /*                             */
    /*           支付相关           */
    /*                             */
    /*-----------------------------*/
    /**
     * 退款链接
     */
    public static final String REFUNDS_URL = "https://api.mch.weixin.qq.com/v3/refund/domestic/refunds";
    public static final String REFUNDS_URi = "/v3/refund/domestic/refunds/";
    /**
     * 其他
     */
    public static final String WECHATPAY_STATUS = "status";
    public static final String WECHATPAY_SUCCESS = "SUCCESS";
    public static final String WECHATPAY_PROCESSING = "PROCESSING";
    public static final String WECHATPAY_OUT_TRADE_NO = "out_trade_no";
    public static final String WECHATPAY_OUT_REFUND_NO = "out_refund_no";
    public static final String WECHATPAY_REFUND = "refund";
    public static final String WECHATPAY_TOTAL = "total";
    public static final String WECHATPAY_CURRENCY = "currency";
    public static final String WECHATPAY_CURRENCY_CNY = "CNY";
    public static final String WECHATPAY_AMOUNT = "amount";
    public static final String WECHATPAY_NOTIFY_URL = "notify_url";

    public static final String REFUNDS_RESOURCE = "resource";
    public static final String REFUNDS_CIPHERTEXT = "ciphertext";
    public static final String REFUNDS_NONCE = "nonce";
    public static final String REFUNDS_REFUND_STATUS = "refund_status";
    public static final String REFUNDS_ASSOCIATED_DATA = "associated_data";
    public static final String WECHAT_ERRCODE = "errcode";
    public static final String WECHAT_ERRMSG = "errmsg";
    /**
     * 退款的token的SCHEMA
     */
    public static final String REFUNDS_SCHEMA = "Wechatpay-Signature-Type "; // 注意有一个空格
    /**
     * 支付请求头
     */
    public static final String WECHATPAY_SIGNATURE_TYPE = "Wechatpay-Signature-Type";
}
