package org.jeecg.modules.adweb.dmp.service.google;

import org.apache.commons.lang3.tuple.Pair;
import org.jeecg.common.util.FastJsonUtil;
import org.jeecg.modules.adweb.dmp.dto.google.analytics.report.GAReportRequestDTO;
import org.jeecg.modules.adweb.dmp.dto.google.analytics.report.ReportType;
import org.jeecg.modules.adweb.dmp.dto.google.analytics.report.data.CountryChartData;
import org.jeecg.modules.adweb.dmp.entity.GoogleGTM;
import org.junit.jupiter.api.Disabled;
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 java.util.List;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("dev")
public class GoogleServiceTest {

    @Autowired GAReportService gaReportService;

    @Autowired GTMAdminService gtmAdminService;

    @Test
    public void testGAReport() {
        GAReportRequestDTO gaReportRequest = new GAReportRequestDTO();
        gaReportRequest.setPropertyResourceName("properties/457183952");
        gaReportRequest.setReportType(ReportType.ADWEB_COUNTRY_CHART);
        gaReportRequest.setStartDate("2023-10-01");
        gaReportRequest.setEndDate("2024-10-01");

        List<CountryChartData> countryReport =
                gaReportService.runGAReport(gaReportRequest, CountryChartData.class);

        System.out.println(FastJsonUtil.toJSONString(countryReport));
    }

    @Test
    @Disabled("GTM + GA帐户资源限制")
    public void testCreateAndDeleteGTMContainer() {
        GoogleGTM googleGTM =
                gtmAdminService.createContainer(
                        "230206anit40",
                        "https://www.sourcingstone.com",
                        "泉州索兴石业有限公司#" + this.getClass().getSimpleName());
        System.out.println(FastJsonUtil.toJSONString(googleGTM));

        gtmAdminService.deleteContainer(googleGTM.getSiteCode());
    }

    @Test
    public void testGetGTMSnippets() {
        Pair<String, String> snippets = gtmAdminService.getSnippets("GTM-T87NNQ4F");
        System.out.println(snippets.getLeft());
        System.out.println(snippets.getRight());
    }
}
