package cn.pluss.platform.ys;

import cn.pluss.platform.util.StringUtil;
import cn.pluss.platform.yinsheng.YsOldSrcMerchantNo;
import cn.pluss.platform.ys.payV2.YsOldPayV2;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Data
@Component
@ConfigurationProperties(prefix = "ys")
public class YsConfig {

    private String auditDomain;

    private String payDomain;

    private String searchDomain;

    private String commonDomain;

    private String otherDomain;

    private String settleDomain;

    private String agentNo;

    private String srcMerchantNo;

    private String pubKey;

    private String priKey;

    private String oldPubKey;

    //收银呗（武汉）科技有限公司
    private YsOldPayV2 oldPayV2;

    /**
     * 进件，图片上传的接口链接
     */
    public static String IMG_UPLOAD;

    /**
     * 进件接口
     */
    public static String MER_AUDIT;

    /**
     * 进件结果查询接口
     */
    public static String MER_RESULT;

    /**
     * 微信认证
     */
    public static String WX_AUTH;

    /**
     * 微信认证取消
     */
    public static String WX_AUTH_CANCEL;

    /**
     * 微信认证状态查询
     */
    public static String WX_AUTH_STATUS;

    /**
     * 微信认证授权状态查询
     */
    public static String WX_AUTHORIZE_STATUS;

    /**
     * 微信反扫接口地址
     */
    public static String WX_BARCODE_PAY;

    /**
     * 微信公众号支付接口地址
     */
    public static String WX_JSAPI_PAY;

    /**
     * 微信小程序支付
     */
    public static String WX_APPLETS_PAY;


    /**
     * 支付宝反扫接口地址
     */
    public static String ALI_BARCODE_PAY;

    /**
     * 支付宝服务窗支付接口地址
     */
    public static String ALI_JSAPI_PAY;


    /**
     * 银联反扫接口地址
     */
    public static String UNI_BARCODE_PAY;

    /**
     * 银联服务窗支付接口地址
     */
    public static String UNI_JSAPI_PAY;


    /**
     * 退款请求地址
     */
    public static String REFUND_PAY;

    /**
     * 退款查询请求地址
     */
    public static String REFUND_QUERY;

    /**
     * 支付订单查询请求地址
     */
    public static String PAY_ORDER_QUERY;

    /**
     * 支付订单详情请求地址
     */
    public static String PAY_ORDER_DETAIL_QUERY;

    /**
     * 获取银联用户标识
     */
    public static String GET_UNION_USER_ID;

    /**
     * 结算提现接口地址
     */
    public static String SETTLE_TRADE;

    /**
     * 提现接口查询地址
     */
    public static String SETTLE_TRADE_QUERY;

    /**
     * 响应状态成功
     */
    public static final String RESULT_SUCCESS_CODE = "success";

    /**
     * 响应状态失败
     */
    public static final String YS_RESULT_FAIL_CODE = "fail";


    public static final String YS_RESULT_PAY_SUCCESS_CODE = "success";

    public static final String YS_RESULT_PAY_FAIL_CODE = "fail";

    public static final String YS_RESULT_WAITPAY_CODE = "waitpay";

    public static final String YS_RESULT_UNKNOW_CODE = "unknow";

    public static final String YS_RESULT_ACCEPT_CODE = "accept";

    public static final String YS_RESULT_DFREVERSE_CODE = "dfreverse";


    @PostConstruct
    public void init() {
        IMG_UPLOAD = auditDomain + "/gateway/file/merchantPic";

        MER_AUDIT = auditDomain + "/gateway/merchant/add";

        MER_RESULT = auditDomain + "/gateway/merchant/query";

        WX_AUTH = auditDomain + "/gateway/merchant/wxAuthSubmitApply";

        WX_AUTH_CANCEL = auditDomain + "/gateway/merchant/wxAuthCancelApply";

        WX_AUTH_STATUS = auditDomain + "/gateway/merchant/wxAuthQueryByApplyNo";

        WX_AUTHORIZE_STATUS = auditDomain + "/gateway/merchant/wxAuthState";

        WX_BARCODE_PAY = payDomain + "/gateway/trade/wxBarCode";

        WX_JSAPI_PAY = payDomain + "/gateway/trade/wxJs";

        WX_APPLETS_PAY = payDomain + "/gateway/trade/wxMiniProgram";

        ALI_BARCODE_PAY = payDomain + "/gateway/trade/alipayBarCode";

        ALI_JSAPI_PAY = payDomain + "/gateway/trade/aliServicePay";

        UNI_BARCODE_PAY = payDomain + "/gateway/trade/ylpayBarCode";

        UNI_JSAPI_PAY = payDomain + "/gateway/trade/ylJsPay";

        REFUND_PAY =  payDomain + "/gateway/trade/applyRefund";

        REFUND_QUERY =  payDomain + "/gateway/trade/queryRefund";

        PAY_ORDER_QUERY =  payDomain + "/gateway/trade/queryOrder";

        PAY_ORDER_DETAIL_QUERY =  payDomain + "/gateway/trade/queryOrderDetail";

        GET_UNION_USER_ID = payDomain + "/gateway/trade/ylUserId";

        SETTLE_TRADE = payDomain + "/gateway/trade/withdraw";

        SETTLE_TRADE_QUERY = payDomain + "/gateway/trade/withdrawQuery";
    }

    public String getPrikeyVal(String srcMerchantNo) {
        //获取秘钥
        if(StringUtil.isEmpty(srcMerchantNo) || YsOldSrcMerchantNo.RSCY.getValue().equals(srcMerchantNo)){
            return this.getPriKey();
        }
        return this.getOldPayV2().getPayPriKey();
    }

    public String getPubKeyVal(String srcMerchantNo) {
        //获取秘钥
        if(StringUtil.isEmpty(srcMerchantNo) || YsOldSrcMerchantNo.RSCY.getValue().equals(srcMerchantNo)){
            return this.getOldPubKey();
        }
        return this.getOldPayV2().getPayPubKey();
    }
}
