package com.njcn.gather.steady.checksquare.component;

import com.njcn.gather.steady.datavie.config.SteadyInfluxDbProperties;
import com.njcn.gather.steady.datavie.pojo.bo.SteadyTrendResolvedFieldBO;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

/**
 * 数据校验 InfluxQL 构造契约测试。
 */
class SteadyChecksquareInfluxQueryComponentTest {

    @Test
    void shouldBuildChecksquareQueryWithoutQualityFlag() {
        SteadyChecksquareInfluxQueryComponent component = new SteadyChecksquareInfluxQueryComponent(new SteadyInfluxDbProperties());
        SteadyTrendResolvedFieldBO field = new SteadyTrendResolvedFieldBO();
        field.setMeasurement("data_v");
        field.setField("rms");
        field.setLineId("line-001");
        field.setPhase("A");
        field.setStatType("AVG");

        String query = component.buildChecksquareQuery(field,
                LocalDateTime.of(2026, 5, 1, 0, 0, 0),
                LocalDateTime.of(2026, 5, 1, 23, 59, 59));

        Assertions.assertTrue(query.contains("SELECT \"rms\" AS \"value\""));
        Assertions.assertTrue(query.contains("\"line_id\" = 'line-001'"));
        Assertions.assertTrue(query.contains("\"phasic_type\" = 'A'"));
        Assertions.assertTrue(query.contains("\"value_type\" = 'AVG'"));
        Assertions.assertFalse(query.contains("quality_flag"));
        Assertions.assertFalse(query.contains("GROUP BY time"));
    }
}
