package cz.senslog.connector.fetch.soilscount;

import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.tools.http.HttpClient;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Optional;

class SoilScountFetcherTest {

    @Test
    void fetch() throws Exception {

        DefaultConfig defaultConfig = new DefaultConfig("id", null);
        defaultConfig.setProperty("startDate", "2024-11-08T00:00:00");
        defaultConfig.setProperty("period", 12);
        defaultConfig.setProperty("allowedDevices", new HashSet<>(Arrays.asList(28779, 28780, 28781, 28782, 28783, 28784, 28785, 28786)));
        defaultConfig.setProperty("authUrl", "https://www.soilscouts.fi/api/v1/auth/login//");
        defaultConfig.setProperty("refreshUrl", "https://www.soilscouts.fi/api/v1/auth/login//");
        defaultConfig.setProperty("devicesUrl", "https://www.soilscouts.fi/api/v1/devices");
        defaultConfig.setProperty("measurementsUrl", "https://www.soilscouts.fi/api/v2/measurements");
        defaultConfig.setProperty("auth", new HashMap<String, String>(){{
            put("username", "mkepka@kgm.zcu.cz");
            put("password", "Asense2023");
        }});


        SoilScountFetcher fetcher = new SoilScountFetcher(new SoilScountConfig(defaultConfig), HttpClient.newHttpClient());

        fetcher.init();
        Optional<SessionModel> session = Optional.of(new SessionModel(true));
        for (int i = 0; i < 10; i++) {
            fetcher.fetch(session);
        }
    }
}