package cz.senslog.connector.fetch.soilscount;

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

import java.time.LocalDateTime;
import java.util.Set;

public class SoilScountConfig {

    public static class AuthConfig {

        private final String username;
        private final String password;

        private AuthConfig(PropertyConfig config) {
            this.username = config.getStringProperty("username");
            this.password = config.getStringProperty("password");
        }

        public String getUsername() {
            return username;
        }

        public String getPassword() {
            return password;
        }
    }

    private final LocalDateTime startDate;
    private final int period;
    private final Set<Integer> allowedDevices;
    private final String authUrl;
    private final String refreshUrl;
    private final String devicesUrl;
    private final String measurementsUrl;
    private final AuthConfig authConfig;

    SoilScountConfig(DefaultConfig defaultConfig) {
        this.startDate = defaultConfig.getLocalDateTimeProperty("startDate");
        this.period = defaultConfig.getIntegerProperty("period");
        this.allowedDevices = defaultConfig.getSetProperty("allowedDevices", Integer.class);
        this.authUrl = defaultConfig.getStringProperty("authUrl");
        this.refreshUrl = defaultConfig.getStringProperty("refreshUrl");
        this.devicesUrl = defaultConfig.getStringProperty("devicesUrl");
        this.measurementsUrl = defaultConfig.getStringProperty("measurementsUrl");
        this.authConfig = new AuthConfig(defaultConfig.getPropertyConfig("auth"));

    }

    public LocalDateTime getStartDate() {
        return startDate;
    }

    public int getPeriod() {
        return period;
    }

    public String getAuthUrl() {
        return authUrl;
    }

    public String getRefreshUrl() {
        return refreshUrl;
    }

    public String getDevicesUrl() {
        return devicesUrl;
    }

    public String getMeasurementsUrl() {
        return measurementsUrl;
    }

    public AuthConfig getAuthConfig() {
        return authConfig;
    }

    public Set<Integer> getAllowedDevices() {
        return allowedDevices;
    }
}
