package com.moka.gdtauto.service;

import com.moka.gdtauto.GdtAutoApplication;
import com.tencent.ads.model.v3.TimeLine;

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;

/**
 * 腾讯广告 日报表同步入库测试
 * https://developers.e.qq.com/v3.0/docs/api/daily_reports/get
 *
 * mvn test -Dtest=DailyReportTest -Dspring.profiles.active=test
 *
 * @author moka
 * @since 2026-03-03
 */
@SpringBootTest(classes = GdtAutoApplication.class)
@ActiveProfiles("test")
class DailyReportTest {

    @Autowired
    private DailyReportService dailyReportService;

    private static final Long ORG_ACCOUNT_ID = 41644744L;
    private static final Long TEST_ACCOUNT_ID = 69781948L;
    private static final String TEST_JOB_NUMBER = "12458";
    private static final Long TEST_GROUP_ID = 1L;
    private static final String TEST_GROUP_NAME = "蒲栋良测试组";

    @Test
    @DisplayName("同步 REQUEST_TIME 口径日报表并入库")
    void testSyncRequestTime() throws Exception {
        System.out.println("\n========================================");
        System.out.println("开始同步 REQUEST_TIME 日报表");
        System.out.println("账户ID: " + TEST_ACCOUNT_ID);
        System.out.println("========================================\n");

        int saved = dailyReportService.syncReport(
                TEST_JOB_NUMBER,
                ORG_ACCOUNT_ID,
                TEST_ACCOUNT_ID,
                TEST_GROUP_ID,
                TEST_GROUP_NAME,
                "2026-02-20",
                "2026-03-03",
                TimeLine.REQUEST_TIME.getValue()
        );
        System.out.println("✅ REQUEST_TIME 同步完成，入库条数: " + saved);
    }

    @Test
    @DisplayName("同步 REPORTING_TIME 口径日报表并入库")
    void testSyncReportingTime() throws Exception {
        System.out.println("\n========================================");
        System.out.println("开始同步 REPORTING_TIME 日报表");
        System.out.println("账户ID: " + TEST_ACCOUNT_ID);
        System.out.println("========================================\n");

        int saved = dailyReportService.syncReport(
                TEST_JOB_NUMBER,
                ORG_ACCOUNT_ID,
                TEST_ACCOUNT_ID,
                TEST_GROUP_ID,
                TEST_GROUP_NAME,
                "2026-02-20",
                "2026-03-03",
                TimeLine.REPORTING_TIME.getValue()
        );
        System.out.println("✅ REPORTING_TIME 同步完成，入库条数: " + saved);
    }
}
