//package org.jk.rag.config;
//
//import org.jk.rag.domain.JkSysOssConfig;
//import org.jk.rag.service.IMinioConfigService;
//import io.minio.MinioClient;
//import okhttp3.OkHttpClient;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.net.ssl.SSLContext;
//import javax.net.ssl.TrustManager;
//import javax.net.ssl.X509TrustManager;
//import java.security.cert.X509Certificate;
//
//@Configuration
//public class MinioConfig {
//
//    @Bean
//    public MinioClient minioClient(@Autowired IMinioConfigService configService) throws Exception {
//        JkSysOssConfig config = configService.getCurrentConfig();
//        // 1. 创建信任所有证书的 TrustManager
//        TrustManager[] trustAllCerts = new TrustManager[]{
//                new X509TrustManager() {
//                    @Override
//                    public void checkClientTrusted(X509Certificate[] chain, String authType) {
//                        // 信任所有客户端证书
//                    }
//
//                    @Override
//                    public void checkServerTrusted(X509Certificate[] chain, String authType) {
//                        // 信任所有服务端证书
//                    }
//
//                    @Override
//                    public X509Certificate[] getAcceptedIssuers() {
//                        return new X509Certificate[0];
//                    }
//                }
//        };
//
//        // 2. 配置 SSLContext
//        SSLContext sslContext = SSLContext.getInstance("TLS");
//        sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
//
//        // 3. 创建 OkHttpClient 并禁用证书验证
//        OkHttpClient httpClient = new OkHttpClient.Builder()
//                .sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0])
//                .hostnameVerifier((hostname, session) -> true) // 跳过主机名验证
//                .build();
//
//        // 4. 初始化 MinIO 客户端
//        return MinioClient.builder()
//                .endpoint(config.getEndpoint())
//                .credentials(config.getAccessKey(), config.getSecretKey())
//                .httpClient(httpClient)
//                .build();
//
////        return MinioClient.builder()
////                .endpoint(config.getEndpoint())
////                .credentials(config.getAccessKey(), config.getSecretKey())
////                .build();
//    }
//
//    @Bean
//    public String minioBucketName(@Autowired IMinioConfigService configService) {
//        return configService.getCurrentConfig().getBucketName();
//    }
//
//
////    @Value("${minio.endpoint}")
////    private String endpoint;
////
////    @Value("${minio.accessKey}")
////    private String accessKey;
////
////    @Value("${minio.secretKey}")
////    private String secretKey;
////
////    @Value("${minio.bucketName}")
////    private String bucketName;
////
////    @Bean
////    public MinioClient minioClient() {
////        return MinioClient.builder()
////                .endpoint(endpoint)
////                .credentials(accessKey, secretKey)
////                .build();
////    }
//
//}
