package cz.senslog.connector.fetch.openmeteo;

import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.model.config.PropertyConfig;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;

public class OpenMeteoConfig {

    public static class Station {
        double latitude, longitude;
        String timezone;
        int past_days;
        List<String> hourly;
        public Station(PropertyConfig stationConfig) {
            this.latitude = stationConfig.getDoubleProperty("latitude");
            this.longitude = stationConfig.getDoubleProperty("longitude");
            this.timezone = stationConfig.getStringProperty("timezone");
            this.past_days = stationConfig.getIntegerProperty("past_days");
            this.hourly = stationConfig.getListProperty("hourly", String.class);
        }
    }

    private final String url;
    private final TimeZone timeZone;
    private final List<Station> stations;

    OpenMeteoConfig(DefaultConfig defaultConfig) {
        this.url = defaultConfig.getStringProperty("baseUrl");
        this.timeZone = TimeZone.getTimeZone(defaultConfig.getStringProperty("timeZone"));
        Set<PropertyConfig> stations = defaultConfig.getSetProperty("allowedStations");
        this.stations = new ArrayList<>(stations.size());
        for (PropertyConfig station : stations) {
            this.stations.add(new Station(station));
        }
    }

    public String getUrl() {
        return url;
    }

    public TimeZone getTimeZone() {
        return timeZone;
    }

    public List<Station> getStations() {
        return stations;
    }
}
