package com.ghb.base.config.oss;

import jakarta.annotation.PostConstruct;
import com.ghb.base.common.util.oss.OssBootUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * 云存储 配置
 * @author: Ghb-boot
 */
@Lazy(false)
@Configuration
@ConditionalOnProperty(prefix = "ghb.oss", name = "endpoint")
public class OssConfiguration {

    @Value("${ghb.oss.endpoint}")
    private String endpoint;
    @Value("${ghb.oss.accessKey}")
    private String accessKeyId;
    @Value("${ghb.oss.secretKey}")
    private String accessKeySecret;
    @Value("${ghb.oss.bucketName}")
    private String bucketName;
    @Value("${ghb.oss.staticDomain:}")
    private String staticDomain;


    @PostConstruct
    public void initOssBootConfiguration() {
        OssBootUtil.setEndPoint(endpoint);
        OssBootUtil.setAccessKeyId(accessKeyId);
        OssBootUtil.setAccessKeySecret(accessKeySecret);
        OssBootUtil.setBucketName(bucketName);
        OssBootUtil.setStaticDomain(staticDomain);
    }
}