package net.northking.cctp.common.s3;

import net.northking.cctp.common.s3.impl.SeaweedFileStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * S3云存储配置
 */
@Import({AmazonS3Properties.class})
@Configuration
public class S3Configuration
{
  private static final Logger logger = LoggerFactory.getLogger(S3Configuration.class);

  @Bean
  public SimpleStorageService s3(AmazonS3Properties s3Properties, AttachmentProducer producer, RedisTemplate redisTemplate) throws Exception
  {
    logger.info("注入seaweed配置");
    SimpleStorageService storageService = new SeaweedFileStorage(s3Properties, producer,redisTemplate);

    logger.info("注册公共组件提示：统一配置 SimpleStorageService 使用 S3云存储服务。");
    return storageService;
  }

  @Bean
  @ConditionalOnMissingBean(AttachmentProducer.class)
  public AttachmentProducer attachmentProducer(RabbitTemplate rabbitTemplate)
  {
    return new AttachMQProducer(rabbitTemplate);
  }

}
