package com.zhentao.config;

import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MinIO配置类
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "minio")
public class MinioConfig {
    
    /**
     * MinIO服务端点
     */
    private String endpoint;
    
    /**
     * 访问密钥
     */
    private String accessKey;
    
    /**
     * 密钥
     */
    private String secretKey;
    
    /**
     * 桶名称
     */
    private String bucketName;
    
    /**
     * 创建MinioClient Bean
     */
    @Bean
    public MinioClient minioClient() {
        System.out.println("========== 初始化MinIO客户端（Admin服务） ==========");
        System.out.println("Endpoint: " + endpoint);
        System.out.println("BucketName: " + bucketName);
        
        try {
            MinioClient client = MinioClient.builder()
                    .endpoint(endpoint)
                    .credentials(accessKey, secretKey)
                    .build();
            
            System.out.println("✓ MinIO客户端初始化成功");
            return client;
        } catch (Exception e) {
            System.err.println("✗ MinIO客户端初始化失败: " + e.getMessage());
            e.printStackTrace();
            throw e;
        }
    }
}

