package com.hdkj.lt.io.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.hdkj.lt.io.mapper.DistSVGFileMapper;
import com.hdkj.lt.io.service.impl.AliyunIObjectStorageServiceImpl;
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({AliyunOSSConfigProperties.class})
@ConditionalOnProperty(prefix = "lt.storage", name = "type", havingValue = "oss")
public class AliyunOSSConfiguration {

    @Bean
    public OSS ossClient(AliyunOSSConfigProperties aliyunOSSConfigProperties) {
        return new OSSClientBuilder().build(
                aliyunOSSConfigProperties.getEndpoint(),
                aliyunOSSConfigProperties.getAccessKeyId(),
                aliyunOSSConfigProperties.getAccessKeySecret());
    }

    @Bean
    public AliyunIObjectStorageServiceImpl objectStorageService(OSS ossClient, DistSVGFileMapper distSVGFileMapper, AliyunOSSConfigProperties aliyunOSSConfigProperties) {
        return new AliyunIObjectStorageServiceImpl(ossClient, distSVGFileMapper, aliyunOSSConfigProperties);
    }

}
