package com.moka.gdtauto.service;

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.alibaba.fastjson2.JSON;
import com.moka.gdtauto.GdtAutoApplication;
import com.moka.gdtauto.common.AutoPlanRule;
import com.moka.gdtauto.entity.AdAutoConf;
import com.moka.gdtauto.entity.AdPlan;

@SpringBootTest(classes = GdtAutoApplication.class)
@ActiveProfiles("test")
public class AdAutoTest {
    
    @Autowired
    private AdPlanService adPlanService;
    @Autowired
    private AdAutoConfService adAutoConfService;
    @Autowired
    private AdPlanAutoExecutor adPlanAutoExecutor;

    @Test
    public void testCheckRule() {
        AdAutoConf conf = adAutoConfService.getById(11);
        adPlanAutoExecutor.checkRule(55L, conf, JSON.parseArray(conf.getRules(), AutoPlanRule.class));
    }

    @Test
    public void testCompareTO() {
        AdPlan plan = adPlanService.lambdaQuery()
            .eq(AdPlan::getAdgroupId, 87878621549L).one();
        AdAutoConf conf = adAutoConfService.getById(7L);
        List<AutoPlanRule> rules = JSON.parseArray(conf.getRules(), AutoPlanRule.class);
        for (AutoPlanRule rule : rules) {
            if (adPlanAutoExecutor.matchRule(plan, rule, 3)) {
                System.out.println("匹配成功: " + JSON.toJSON(rule));
            }
        }
    }



}
