package cz.senslog.analytics.utils.validator;

import cz.senslog.analytics.domain.AttributeType;
import cz.senslog.analytics.domain.ThresholdDimension;
import cz.senslog.analytics.domain.VariableType;
import org.junit.jupiter.api.Test;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME;

class MessageFormatterTest {

    @Test
    void isValid() {

        final String test1 = "V Modulu $module hodnota $val(%.2f) překročila práh $VAL >= 25 °C v čase $timestamp.";
        final String test2 = "$val >= 25 & 12h <= $timestamp(HH:mm) <= 15h v čase $timestamp.";
        final String test3 = "$timestamp | $val";

        List<ThresholdDimension> thresholdDimensions = List.of(
                ThresholdDimension.of(1, null, AttributeType.VAL, null),
                ThresholdDimension.of(2, null, AttributeType.TIME, null)
        );

        MessageFormatter formatter = MessageFormatter.create();
        for (String test : new String[]{test1, test2, test3}) {

            String message = formatter.format(test,
                    Map.of(
                            AttributeType.TIME, 48800.0,
                            AttributeType.VAL, 25.3432
                    ),
                    Map.of(
                            VariableType.TIMESTAMP, f -> OffsetDateTime.now().format(f.map(DateTimeFormatter::ofPattern).orElse(ISO_OFFSET_DATE_TIME)))
            );

            System.out.println(message);
        }
    }
}