package com.yaoai.storage.config;

import com.volcengine.tos.TOSV2;
import com.volcengine.tos.TOSV2ClientBuilder;
import com.volcengine.tos.TOSClientConfiguration;
import com.volcengine.tos.auth.StaticCredentials;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
@ConditionalOnProperty(name = "storage.local.enabled", havingValue = "false", matchIfMissing = true)
public class TosConfig {

    private final TosProperties properties;

    @Bean
    public TOSV2 tosClient() {
        TOSClientConfiguration config = TOSClientConfiguration.builder()
                .endpoint(properties.getEndpoint())
                .region(properties.getRegion())
                .credentials(new StaticCredentials(
                        properties.getAccessKey(),
                        properties.getSecretKey()))
                .build();
        return new TOSV2ClientBuilder().build(config);
    }
}
