package com.moka.gdtauto.service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

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 com.moka.gdtauto.GdtAutoApplication;
import com.moka.gdtauto.task.AdPlanDailyReportSyncTask;
import com.tencent.ads.model.v3.TimeLine;



/**
 * 广告计划日报同步测试
 * mvn test -Dtest=AdPlanDailyReportSyncTest#testSyncDailyCreativeReport -Dspring.profiles.active=test
 */
@SpringBootTest(classes = GdtAutoApplication.class)
@ActiveProfiles("test")
public class AdPlanDailyReportSyncTest {
    
    @Autowired
    private AdPlanDailyReportSyncTask adPlanDailyReportSyncTask;
    @Autowired
    private AdPlanDailyReportService adPlanDailyReportService;
    @Autowired
    private DailyCreativeReportService dailyCreativeReportService;
    @Autowired
    private DailyAdgroupReportService dailyAdgroupReportService;

    @Test
    public void testSyncReqDailyReport() {
        LocalDateTime now = LocalDateTime.now();
        adPlanDailyReportService.syncReqDailyReport(29L, now, now);
    }

    @Test
    public void testSyncRepDailyReport() {
        LocalDateTime now = LocalDateTime.now();
        adPlanDailyReportService.syncRepDailyReport(29L, now, now);
    }


    @Test
    public void testSyncDailyCreativeReport() {
        DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String today = LocalDate.now().format(FMT);
        dailyCreativeReportService.syncAllAccounts(62L, today, today, TimeLine.REQUEST_TIME.getValue());
    }

    @Test
    public void testSyncTenDaysDailyCreativeReport() {
        DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        for (int i = 0; i < 10; i++) {
            String day = LocalDate.now().plusDays(-i).format(FMT);
            dailyCreativeReportService.syncAllAccounts(null, day, day, TimeLine.REQUEST_TIME.getValue());
            dailyCreativeReportService.syncAllAccounts(null, day, day, TimeLine.REPORTING_TIME.getValue());
        }
    }

    @Test
    public void testSyncDailyAdgroupReport() {
        DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String today = LocalDate.now().plusDays(-1).format(FMT);
        dailyAdgroupReportService.syncAllAccounts(62L, today, today, TimeLine.REQUEST_TIME.getValue());
    }

    // mvn test -Dtest=AdPlanDailyReportSyncTest#testSyncTenDaysDailyAdgroupReport -Dspring.profiles.active=test
    @Test
    public void testSyncTenDaysDailyAdgroupReport() {
        DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        for (int i = 0; i < 10; i++) {
            String day = LocalDate.now().plusDays(-i).format(FMT);
            dailyAdgroupReportService.syncAllAccounts(62L, day, day, TimeLine.REQUEST_TIME.getValue());
            dailyAdgroupReportService.syncAllAccounts(62L, day, day, TimeLine.REPORTING_TIME.getValue());
        }
    }
}
