package cz.senslog.analytics;

import cz.senslog.analytics.domain.*;
import cz.senslog.analytics.utils.validator.NotifyTrigger;
import io.vertx.core.json.JsonObject;

import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static cz.senslog.analytics.messaging.MessageBroker.Type.SENSLOG_ALERT;

public class MockData {

    public static final long uniqueSensorId = 100L;
    public static final long groupId = 1L;
    public static final long unitId = 100000;
    public static final long sensorId = 10343;
    public static final double observationValue = 25.3;

    public static final Sensor sensor = new Sensor(uniqueSensorId, unitId, sensorId);
    public static final Observation observation = new Observation(sensor, observationValue, OffsetDateTime.now());

    public static final Group doubleGroup = Group.of(groupId, "Rostenice_Temperature", CollectorType.DOUBLE);

    public static Map<Sensor, List<Group>> mockSensorToGroupConfig() {
        return Map.of(sensor, List.of(doubleGroup));
    }

    public static List<Threshold> mockThresholdsConfigForSensors() {
        return List.of(new Threshold(1, uniqueSensorId, NotifyTrigger.Type.INSTANT, true, AttributeName.VAL, List.of(
                        new ThresholdRule("gt", 10.0)
        )));
    }

    public static List<Threshold> mockThresholdsConfigForGroups(CollectorType type) {
        if (Objects.requireNonNull(type) == CollectorType.DOUBLE) {
            return List.of(new Threshold(2, doubleGroup.id(), NotifyTrigger.Type.INSTANT, true, AttributeName.MIN, List.of(
                    new ThresholdRule("lt", 0.0),
                    new ThresholdRule("gt", 10.0)))
            );
        }
        return Collections.emptyList();
    }

    public static Map<Long, Group> mockGroupsConfig(CollectorType type) {
        if (Objects.requireNonNull(type) == CollectorType.DOUBLE) {
            return Map.of(doubleGroup.id(), doubleGroup);
        }
        return Collections.emptyMap();
    }

    public static List<MessageBrokerConfig> mockMessageBrokers() {
        return List.of(
                new MessageBrokerConfig(1L, SENSLOG_ALERT, JsonObject.of())
        );
    }

    public static List<SourceToMessageBroker> mockSourceToMessageBroker() {
        return List.of(
                new SourceToMessageBroker(uniqueSensorId, 1L, JsonObject.of()),
                new SourceToMessageBroker(groupId, 1L, JsonObject.of())
        );
    }
}
