package com.wzj.soopin.content.utils;

import com.qcloud.vod.VodUploadClient;
import com.qcloud.vod.model.VodUploadRequest;
import com.qcloud.vod.model.VodUploadResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;


@Component
public class QcCloud {
    @Autowired
    private TencentCloudProperties tencentCloudProperties;
    public String getSecretId() {
        return tencentCloudProperties.getSecretId();
    }

    public String getSecretKey() {
        return tencentCloudProperties.getSecretKey();
    }

    public String getRegion() {
        return "ap-guangzhou";// 腾讯云 VOD 和 COS 使用相同区域
    }



    public String[] uploadViaTempFile(Path filePath) throws Exception {
        //确保 vlogdata 目录存在
        // 组装完整的文件路径
        File sourceFile = new File(filePath.toString());
        System.out.println("腾讯云服务：完整文件路径: " + filePath);

        if (!sourceFile.exists()) {
            throw new RuntimeException("腾讯云服务：文件不存在: " + sourceFile.getAbsolutePath());
        }
        try {
            VodUploadClient client = new VodUploadClient(getSecretId(), getSecretKey());
            VodUploadRequest request = new VodUploadRequest();
            request.setMediaFilePath(sourceFile.getAbsolutePath());// 指定本地文件路径
            request.setProcedure("视频处理");  // 智能审核+水印
            // 上传文件
            VodUploadResponse response = client.upload(getRegion(), request);
//            return response;
            return new String[]{response.getFileId(), response.getMediaUrl()};
        }catch (Exception e){
            throw new RuntimeException("腾讯云服务：上传文件失败: " + e.getMessage());
        }
    }
}
