package com.kcim.common.file;

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

/**
 * url: http://118.31.245.65:9000/
 * access-key: admin
 * secret-key: xywl2021701
 * bucket-name: test
 */

/**
 * @Component 每次返回的对象不同 类似于多例 用于解决全局变量不一致的问题
 * @Configuration 每次从spring容器中获取保证每次都是同一个实例对象 类似单例
 */
@Configuration
@Data
@ConfigurationProperties(prefix = "minio")
public class MinioConfig {

    private String url;

    private Integer port;

    private String accessKey;

    private String secretKey;

    private String bucketName;


    @Bean
    public MinioClient minioClient() throws InvalidPortException, InvalidEndpointException {
        try {
            return new MinioClient(url, accessKey, secretKey);
        } catch (InvalidEndpointException e) {
            throw new RuntimeException(e);
        } catch (InvalidPortException e) {
            throw new RuntimeException(e);
        }
    }

}
