package com.moka.gdtauto.service;

import java.time.LocalDateTime;
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 com.moka.gdtauto.GdtAutoApplication;
import com.moka.gdtauto.entity.AdPlanConf;

@SpringBootTest(classes = GdtAutoApplication.class)
@ActiveProfiles("test")
public class AdAutoDeleteTest {
    @Autowired
    private AdPlanConfService adPlanConfService;

    @Test
    public void testDelete() {
        List<Long> confIds = List.of(36L,37L,43L,44L,45L,51L);
        for (Long confId : confIds) {
            AdPlanConf adPlanConf = adPlanConfService.getById(confId);
            adPlanConfService.gdtAdgroupPatrolDelete(adPlanConf);
        }
    }


    @Test
    public void testPatrolDelete() {
        //3天前
        LocalDateTime threeDaysAgo = LocalDateTime.now().minusDays(3);
        List<AdPlanConf> confList = 
            adPlanConfService.lambdaQuery()
            .lt(AdPlanConf::getCreateTime, threeDaysAgo)
            .orderByDesc(AdPlanConf::getId)
            .list();
        confList.forEach(conf -> adPlanConfService.gdtAdgroupPatrolDelete(conf));
    }
}
