package com.njzscloud.common.minio.config;

import com.njzscloud.common.minio.controller.OSSController;
import io.minio.MinioAsyncClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(MinioProperties.class)
public class MinioAutoConfiguration {

    @Bean(destroyMethod = "close")
    public MinioAsyncClient minioClient(MinioProperties minioProperties) {
        String endpoint = minioProperties.getEndpoint();
        String accessKey = minioProperties.getAccessKey();
        String secretKey = minioProperties.getSecretKey();
        return MinioAsyncClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }

    @Bean
    public OSSController ossController() {
        return new OSSController();
    }
}
