package com.moka.gdtauto.service;

import java.time.LocalDate;
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.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 AdPlanCreativeDailyReportService adPlanCreativeDailyReportService;
    @Autowired
    private AdPlanDailyReportService adPlanDailyReportService;
    @Autowired
    private DailyCreativeReportService dailyCreativeReportService;
    @Autowired
    private DailyAdgroupReportService dailyAdgroupReportService;

    @Test
    public void testSyncDailyReport() {
        try {
            adPlanDailyReportService.syncDailyReport(67L);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testSyncCreativeReport() {
        try {
            adPlanCreativeDailyReportService.syncDailyReport(67L);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @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());
    }

    // mvn test -Dtest=AdPlanDailyReportSyncTest#testSyncTenDaysDailyCreativeReport -Dspring.profiles.active=test
    @Test
    public void testSyncTenDaysDailyCreativeReport() {
        DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            String start = LocalDate.now().plusDays(-5).format(FMT);
            String end = LocalDate.now().format(FMT);
            dailyCreativeReportService.syncAllAccounts(null, start, end, TimeLine.REQUEST_TIME.getValue());
            dailyCreativeReportService.syncAllAccounts(null, start, end, 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");
            String start = LocalDate.now().plusDays(-2).format(FMT);
            String day = LocalDate.now().format(FMT);
            dailyAdgroupReportService.syncAllAccounts(null, start, day, TimeLine.REQUEST_TIME.getValue());
            dailyAdgroupReportService.syncAllAccounts(null, start, day, TimeLine.REPORTING_TIME.getValue());
    }
}
