package com.vetti.common.config;


import io.minio.MinioClient;
import lombok.Data;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Data
@Configuration
public class MinioConfig {

    @Value("${fs.minio.endpoint}")
    private String endpoint;

    @Value("${fs.minio.access-key}")
    private String accessKey;

    @Value("${fs.minio.secret-key}")
    private String secretKey;


    // 1. 配置 OkHttp 客户端（设置超时参数）
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .connectTimeout(300, TimeUnit.SECONDS)   // 连接超时
            .readTimeout(600, TimeUnit.SECONDS)      // 读取超时
            .writeTimeout(600, TimeUnit.SECONDS)     // 写入超时
            .retryOnConnectionFailure(true)         // 连接失败重试
            .build();

    /**
     * 创建 MinIO 客户端实例
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .httpClient(okHttpClient)
                .build();
    }
}
