package cz.senslog.connector.fetch.openmeteo;

import cz.senslog.connector.fetch.api.ExecutableFetcher;
import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.model.metno.MetnoModel;
import cz.senslog.connector.model.openmeteo.OpenMeteoModel;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

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

class OpenMeteoFetcherTest {

    @Test
    void fetch() throws Exception {
        ConnectorFetchOpenMeteoProvider provider = new ConnectorFetchOpenMeteoProvider();

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

//        defaultConfig.setProperty("baseUrl", "https://previous-runs-api.open-meteo.com/v1/forecast");
        defaultConfig.setProperty("baseUrl", "https://archive-api.open-meteo.com/v1/archive");
        defaultConfig.setProperty("timeZone", "Europe/Prague");
        defaultConfig.setProperty("startDate", "2024-01-01");

        defaultConfig.setProperty("allowedStationURL", "https://sensor.lesprojekt.cz/senslogOTS3/rest/forecast/era5land/plan");
        Map<String, Object> params = new HashMap<String, Object>(){{
            put("models", "era5_land");
            put("hourly", Arrays.asList("temperature_2m", "relative_humidity_2m", "dew_point_2m", "precipitation", "rain", "snowfall", "pressure_msl", "surface_pressure",
                    "et0_fao_evapotranspiration", "cloud_cover","wind_speed_10m", "wind_direction_10m", "wind_gusts_10m",
                    "soil_temperature_0_to_7cm","soil_temperature_7_to_28cm","soil_temperature_28_to_100cm","soil_temperature_100_to_255cm",
                    "soil_moisture_0_to_7cm","soil_moisture_7_to_28cm","soil_moisture_28_to_100cm","soil_moisture_100_to_255cm"));
        }};
        defaultConfig.setProperty("allowedStationURLParams", params);

//        Map<String, Object> st1 = new HashMap<String, Object>() {{
//            put("latitude", 49.72680307543005);
//            put("longitude", 13.351931666613327);
//            put("timezone", "GMT");
//            put("past_days", 1);
//            put("hourly", Arrays.asList("temperature_2m","temperature_2m_previous_day1","temperature_2m_previous_day2","temperature_2m_previous_day3","temperature_2m_previous_day4","temperature_2m_previous_day5",
//                    "relative_humidity_2m","relative_humidity_2m_previous_day1","relative_humidity_2m_previous_day2","relative_humidity_2m_previous_day3","relative_humidity_2m_previous_day4","relative_humidity_2m_previous_day5",
//                    "dew_point_2m","dew_point_2m_previous_day1","dew_point_2m_previous_day2","dew_point_2m_previous_day3","dew_point_2m_previous_day4","dew_point_2m_previous_day5",
//                    "apparent_temperature","apparent_temperature_previous_day1","apparent_temperature_previous_day2","apparent_temperature_previous_day3","apparent_temperature_previous_day4","apparent_temperature_previous_day5",
//                    "precipitation","precipitation_previous_day1","precipitation_previous_day2","precipitation_previous_day3","precipitation_previous_day4","precipitation_previous_day5",
//                    "rain","rain_previous_day1","rain_previous_day2","rain_previous_day3","rain_previous_day4","rain_previous_day5",
//                    "showers","showers_previous_day1","showers_previous_day2","showers_previous_day3","showers_previous_day4","showers_previous_day5",
//                    "snowfall","snowfall_previous_day1","snowfall_previous_day2","snowfall_previous_day3","snowfall_previous_day4","snowfall_previous_day5",
//                    "weather_code","weather_code_previous_day1","weather_code_previous_day2","weather_code_previous_day3","weather_code_previous_day4","weather_code_previous_day5",
//                    "pressure_msl","pressure_msl_previous_day1","pressure_msl_previous_day2","pressure_msl_previous_day3","pressure_msl_previous_day4","pressure_msl_previous_day5",
//                    "surface_pressure","surface_pressure_previous_day1","surface_pressure_previous_day2","surface_pressure_previous_day3","surface_pressure_previous_day4","surface_pressure_previous_day5",
//                    "cloud_cover","cloud_cover_previous_day1","cloud_cover_previous_day2","cloud_cover_previous_day3","cloud_cover_previous_day4","cloud_cover_previous_day5",
//                    "wind_speed_10m","wind_speed_10m_previous_day1","wind_speed_10m_previous_day2","wind_speed_10m_previous_day3","wind_speed_10m_previous_day4","wind_speed_10m_previous_day5",
//                    "wind_direction_10m","wind_direction_10m_previous_day1","wind_direction_10m_previous_day2","wind_direction_10m_previous_day3","wind_direction_10m_previous_day4","wind_direction_10m_previous_day5"));
//        }};

//        defaultConfig.setProperty("allowedStations", Collections.singletonList(st1));

        ExecutableFetcher<OpenMeteoModel> fetcher = provider.createExecutableFetcher(defaultConfig);
        fetcher.getRawFetcher().init();
        fetcher.execute();

    }
}