package com.fdkankan.pay.alipay.sdk;

import com.alipay.demo.trade.service.AlipayTradeService;
import com.alipay.demo.trade.service.impl.AlipayTradeServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public abstract class AlipayConfig {

    /** 签名类型 */
    private String signType = "RSA2";
    /** 格式 */
    private String formate = "json";
    /** 编码 */
    private String charset = "UTF-8";
    /** 最大查询次数 */
    private int maxQueryRetry = 5;
    /** 查询间隔（毫秒） */
    private long queryDuration = 5000;
    /** 最大撤销次数 */
    private int maxCancelRetry = 3;
    /** 撤销间隔（毫秒） */
    private long cancelDuration = 3000;

    /** 支付宝gatewayUrl */
    abstract public String getGatewayUrl();

    /** 商户应用id */
    abstract public String getAppid();

    /** RSA私钥，用于对商户请求报文加签 */
    abstract public String getAppPrivateKey();

    /** 支付宝RSA公钥，用于验签支付宝应答 */
    abstract public String getAlipayPublicKey();

    /** 同步地址 */
    abstract public String getReturnUrl();
    /** 异步地址 */
    abstract public String getNotifyUrl();

    public String getSignType(){
        return signType;
    }

    public String getFormate(){
        return formate;
    }

    public String getCharset(){
        return charset;
    }

    public int getMaxQueryRetry() {
        return maxQueryRetry;
    }

    public long getQueryDuration() {
        return queryDuration;
    }

    public int getMaxCancelRetry() {
        return maxCancelRetry;
    }

    public long getCancelDuration() {
        return cancelDuration;
    }

    @Bean
    public AlipayTradeService alipayTradeService() {
        return new AlipayTradeServiceImpl.ClientBuilder()
                .setGatewayUrl(getGatewayUrl())
                .setAppid(getAppid())
                .setPrivateKey(getAppPrivateKey())
                .setAlipayPublicKey(getAlipayPublicKey())
                .setSignType(getSignType())
                .build();
    }
}
