package com.xunhong.erp.turbo.file.config;

import com.xunhong.erp.turbo.file.FileService;
import com.xunhong.erp.turbo.file.OssServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
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;

/**
 * @author shenyifei
 */
@Configuration
@EnableConfigurationProperties(OssProperties.class)
@RequiredArgsConstructor
public class OssConfiguration {
	private final OssProperties properties;

	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(prefix = OssProperties.PREFIX, value = "enabled", havingValue = "true")
//	@Profile({"default", "prod"})
	public FileService ossService() {
		OssServiceImpl ossService = new OssServiceImpl();
		ossService.setBucket(properties.getBucket());
		ossService.setRegion(properties.getRegion());
		ossService.setRoleArn(properties.getRoleArn());
		ossService.setStsEndPoint(properties.getStsEndPoint());
		ossService.setOssEndPoint(properties.getOssEndPoint());
		ossService.setAccessKey(properties.getAccessKey());
		ossService.setAccessSecret(properties.getAccessSecret());
		ossService.setPolicy(properties.getPolicy());
		return ossService;
	}

//	@Bean
//	@ConditionalOnMissingBean
//	@Profile({"dev", "test"})
//	public FileService mockFileService() {
//		return new MockFileServiceImpl();
//	}
}
