package com.hdkj.lt.io.config;

import com.hdkj.lt.io.mapper.DistSVGFileMapper;
import com.hdkj.lt.io.service.impl.MinioIObjectStorageServiceImpl;
import io.minio.MinioClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description
 * @Author wcx
 * @Date 2025/6/18 16:19
 * @Version 1.0
 */
@Configuration
@EnableConfigurationProperties({MinioOSSConfigProperties.class})
@ConditionalOnProperty(prefix = "lt.storage", name = "type", havingValue = "minio")
public class MinioOSSConfiguration {

    @Bean
    public MinioClient minioClient(MinioOSSConfigProperties minioOSSConfigProperties) {
        return MinioClient.builder()
                .endpoint(minioOSSConfigProperties.getEndpoint())
                .credentials(minioOSSConfigProperties.getAccessKey(), minioOSSConfigProperties.getSecretKey())
                .build();
    }


    @Bean
    public MinioIObjectStorageServiceImpl objectStorageService(MinioClient minioClient, DistSVGFileMapper distSVGFileMapper, MinioOSSConfigProperties minioOSSConfigProperties) {
        return new MinioIObjectStorageServiceImpl(minioClient, distSVGFileMapper, minioOSSConfigProperties);
    }

}
