package com.czg.third.wechat;

import com.czg.third.wechat.dto.config.WechatPayConfigDto;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAPublicKeyConfig;
import com.wechat.pay.java.service.file.FileUploadService;

/**
 * 微信支付 配置
 *
 * @author yjjie
 * @date 2025/12/26 09:33
 */
public class WechatConfig {

    /**
     * 获取微信支付配置
     * @param dto 微信支付配置
     * @return 微信支付配置
     */
    public static Config getRsaConfig(WechatPayConfigDto dto) {
        if (dto == null) {
            dto = WechatPayConfigDto.getDefaultConfig();
        }
        return new RSAPublicKeyConfig.Builder()
                .merchantId(dto.getMerchantId())
                .privateKey(dto.getPrivateKey())
                .publicKey(dto.getPublicKey())
                .publicKeyId(dto.getPublicKeyId())
                .merchantSerialNumber(dto.getSerialNumber())
                .apiV3Key(dto.getApiV3Key())
                .build();
    }

    public static FileUploadService getFileUploadServiceByConfig(Config config) {
        return new FileUploadService.Builder()
                .config(config)
                .build();
    }

    /**
     * 获取文件上传服务
     * @param dto 微信支付配置
     * @return 文件上传服务
     */
    public static FileUploadService getFileUploadService(WechatPayConfigDto dto) {
        return getFileUploadServiceByConfig(getRsaConfig(dto));
    }

}
