package com.moka.gdtauto.service;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import lombok.extern.slf4j.Slf4j;

import com.moka.gdtauto.GdtAutoApplication;
import com.moka.gdtauto.client.TencentAdsApiClientFactory;
import com.moka.gdtauto.entity.OssFile;
import com.tencent.ads.model.v3.BrandAddResponseData;
import com.tencent.ads.model.v3.ImagesAddResponseData;
import com.tencent.ads.model.v3.VideosAddResponseData;
import com.tencent.ads.v3.TencentAds;

/**
 * mvn test -Dtest=OssFileTencentUploadTest#testUploadFile -Dspring.profiles.active=test
 */
@SpringBootTest(classes = GdtAutoApplication.class)
@ActiveProfiles("test")
@Slf4j
public class OssFileTencentUploadTest {

    @Autowired
    private OssFileService ossFileService;
    @Autowired
    private TencentAdsApiClientFactory clientFactory;
    @Autowired
    private TencentAssetService tencentAssetService;

    private static final Long ORG_ACCOUNT_ID = 44035150L;
    private static final String TEST_JOB_NUMBER = "12458";

    @Test
    public void testUploadFile() throws Exception {
        List<OssFile> ossFileList = ossFileService.lambdaQuery()
        .eq(OssFile::getBusinessType, 1)
        .in(OssFile::getId, List.of(79))
        .list();
        TencentAds tencentAds = clientFactory.getTencentAds(TEST_JOB_NUMBER, ORG_ACCOUNT_ID);
            tencentAds.setDebug(true);
            ossFileList.forEach(ossFile -> {
            try {
                tencentAssetService.uploadAsset(ossFile);
                ossFileService.updateById(ossFile);
            } catch(Exception e) {
                e.printStackTrace();
            }
        });
        
    }
    
}
