package com.moka.gdtauto.integration;

import com.alibaba.fastjson2.JSON;
import com.moka.gdtauto.GdtAutoApplication;
import com.moka.gdtauto.service.TencentAdsAccountService;
import com.tencent.ads.model.v3.AdgroupsGetResponseData;

import org.junit.jupiter.api.DisplayName;
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;

/**
 * 广告组API手动测试
 * 用于手动调用腾讯广告API并查看返回结果
 * 
 * @author moka
 * @since 2026-02-04
 */
@SpringBootTest(classes = GdtAutoApplication.class)
@ActiveProfiles("test")
class AdgroupsApiManualTest {

    @Autowired
    private TencentAdsAccountService accountService;

   private static final Long ORG_ACCOUNT_ID = 33453856L;
   private static final String TEST_JOB_NUMBER = "12458";
    private static final Long TEST_ACCOUNT_ID = 69781948L;

    @Test
    @DisplayName("手动测试-获取广告组列表第1页")
    void testGetAdgroupsFirstPage() {
        System.out.println("\n========================================");
        System.out.println("开始获取广告组列表");
        System.out.println("账户ID: " + TEST_ACCOUNT_ID);
        System.out.println("========================================\n");

        try {
            // 调用SDK获取第1页,10条数据
            System.out.println("正在调用腾讯广告API...");
            AdgroupsGetResponseData response = accountService.getAdgroups(TEST_JOB_NUMBER, ORG_ACCOUNT_ID, TEST_ACCOUNT_ID, 1L, 10L);

            // 将返回结果JSON化输出
            System.out.println("\n========== API返回结果(JSON格式) ==========");
            String jsonResult = JSON.toJSONString(response);
            System.out.println(jsonResult);
            System.out.println("========================================\n");

            // 输出摘要信息
            if (response != null && response.getList() != null) {
                System.out.println("✅ 成功获取广告组列表");
                System.out.println("📊 返回数据条数: " + response.getList().size());
                
                if (response.getPageInfo() != null) {
                    System.out.println("📄 分页信息:");
                    System.out.println("   - 当前页: " + response.getPageInfo().getPage());
                    System.out.println("   - 每页数量: " + response.getPageInfo().getPageSize());
                    System.out.println("   - 总数: " + response.getPageInfo().getTotalNumber());
                }
            } else {
                System.out.println("⚠️  返回结果为空");
            }

        } catch (Exception e) {
            System.err.println("\n❌ API调用失败");
            System.err.println("错误信息: " + e.getMessage());
            e.printStackTrace();
            throw new RuntimeException("测试失败", e);
        }
    }
}
