package cz.senslog.connector.fetch.senslog.v1;

import cz.senslog.connector.model.analytics.AnalyticsModel;
import cz.senslog.connector.model.converter.Senslog1ModelAnalyticsModelConverter;
import cz.senslog.connector.model.converter.SenslogV1ModelAFarCloudModelConverter;
import cz.senslog.connector.model.v1.SenslogV1Model;
import cz.senslog.connector.tools.http.HttpClient;
import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.tools.json.BasicJson;
import org.junit.jupiter.api.Test;

import java.time.*;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;

class SenslogFetcherTest {


    @Test
    void fetch() throws Exception {

        DefaultConfig defaultConfig = new DefaultConfig("", null);

        defaultConfig.setProperty("startDate", "now");
        defaultConfig.setProperty("timeZone", "Europe/Prague");
        defaultConfig.setProperty("baseUrl", "http://sensor.lesprojekt.cz/senslog15");
        defaultConfig.setProperty("user", "osek");
        defaultConfig.setProperty("interval", 20);

        Map<String, String> auth = new HashMap<>();
        auth.put("username", "osek");
        auth.put("password", "oSek");
        defaultConfig.setProperty("auth", auth);

        Map<String, List<Long>> allowedStation = new HashMap<>();
        allowedStation.put("1305167549174391", Collections.singletonList(340070001L));
        defaultConfig.setProperty("allowedStation", allowedStation);

        SenslogConfig config = new SenslogConfig(defaultConfig);
        SenslogFetcher fetcher = new SenslogFetcher(config, HttpClient.newHttpClient());
        Senslog1ModelAnalyticsModelConverter converter = new Senslog1ModelAnalyticsModelConverter();

        fetcher.init();

        SensLogSession session = new SensLogSession(true);

        AnalyticsModel a1 = converter.convert(fetcher.fetch(Optional.of(session)));
        System.out.println(BasicJson.objectToJson(a1.getObservations()));

        AnalyticsModel a2 = converter.convert(fetcher.fetch(Optional.of(session)));
        System.out.println(BasicJson.objectToJson(a2.getObservations()));
    }

}