package com.dora.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 腾讯云 COS 配置类
 */
@Configuration
@ConfigurationProperties(prefix = "tencent.cos")
@Data
public class CosConfig {

    /**
     * SecretId
     */
    private String secretId;

    /**
     * SecretKey
     */
    private String secretKey;

    /**
     * 地域，例如 ap-guangzhou
     */
    private String region;

    /**
     * 存储桶名称，例如 example-1250000000
     */
    private String bucketName;

    /**
     * 用户图片文件夹
     */
    private String userImgFolder = "user_img/";

    /**
     * 预签名 URL 过期时间（秒）
     */
    private Long expirationSeconds = 3600L;

    /**
     * 自定义访问域名（如配置了 CDN/自定义域名），可选
     */
    private String customDomain;

    /**
     * 创建 COS 客户端
     */
    @Bean
    public COSClient cosClient() {
        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
        ClientConfig clientConfig = new ClientConfig(new Region(region));
        return new COSClient(cred, clientConfig);
    }
}
