package com.xy.xyaicpzs.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 配置类
 *
 * @author xy
 */
@Configuration
@ConfigurationProperties(prefix = "cos")
@Data
public class CosConfig {

    /**
     * SecretId
     */
    private String secretId;

    /**
     * SecretKey
     */
    private String secretKey;

    /**
     * 存储桶名称
     */
    private String bucketName;

    /**
     * 地域
     */
    private String region;

    /**
     * 访问域名
     */
    private String domain;

    /**
     * 创建 COSClient 实例
     */
    @Bean
    public COSClient cosClient() {
        // 初始化用户身份信息（secretId, secretKey）
        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
        
        // 设置 bucket 的地域
        Region regionObj = new Region(region);
        ClientConfig clientConfig = new ClientConfig(regionObj);
        
        // 生成 cos 客户端
        return new COSClient(cred, clientConfig);
    }
}
