package com.copy.trade.bean;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@ConfigurationProperties(prefix = "s3")
@Component
public class S3Config {

    private String accessKeyId;

    private String accessKeySecret;

    private String bucketName;

    private String region = "ap-southeast-1";

    private String endpoint;

    public String toUrl(String key) {
        if (endpoint != null && !endpoint.isEmpty()) {
            return String.format("https://%s/%s/%s", endpoint, bucketName, key);
        }
        return String.format("https://%s.s3.%s.amazonaws.com/%s", bucketName, region, key);
    }
}
