package cz.senslog.connector.fetch.fieldclimate;

import cz.senslog.connector.fetch.fieldclimate.auth.AuthConfig;
import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.model.config.HostConfig;

import java.time.LocalDateTime;
import java.util.TimeZone;

public class FieldClimateConfig {

    private final LocalDateTime startDate;
    private final HostConfig stationsHost;
    private final HostConfig stationDataHost;
    private final HostConfig stationTimeRangeHost;
    private final AuthConfig authentication;
    private final Integer period;
    private final FieldClimateSessionProxyConfig sessionProxy;
    private final AllowedStation allowedStation;
    private final TimeZone timeZone;

    public FieldClimateConfig(DefaultConfig config) {
        this.startDate = config.getLocalDateTimeProperty("startDate");
        this.stationsHost = new HostConfig(config.getPropertyConfig("stationsHost"));
        this.stationDataHost = new HostConfig(config.getPropertyConfig("stationDataHost"));
        this.stationTimeRangeHost = new HostConfig(config.getPropertyConfig("stationTimeRangeHost"));
        this.authentication = new AuthConfig(config.getPropertyConfig("authentication"));
        this.period = config.getIntegerProperty("period");
        this.timeZone = TimeZone.getTimeZone(config.getStringProperty("timeZone"));

        this.sessionProxy = config.containsProperty("sessionProxy") ?
                new FieldClimateSessionProxyConfig(config.getPropertyConfig("sessionProxy")) : null;

        this.allowedStation = new AllowedStation(config.getPropertyConfig("allowedStation"));
    }

    public LocalDateTime getStartDate() {
        return startDate;
    }

    public HostConfig getStationsHost() {
        return stationsHost;
    }

    public HostConfig getStationDataHost() {
        return stationDataHost;
    }

    public HostConfig getStationTimeRangeHost() {
        return stationTimeRangeHost;
    }

    public AuthConfig getAuthentication() {
        return authentication;
    }

    public Integer getPeriod() {
        return period;
    }

    public AllowedStation getAllowedStation() {
        return allowedStation;
    }

    public TimeZone getTimeZone() {
        return timeZone;
    }

    public FieldClimateSessionProxyConfig getSessionProxy() {
        return sessionProxy;
    }
}
