package cz.senslog.connector.fetch.azure.auth;

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

import java.util.Optional;

import static java.util.Optional.ofNullable;

/**
 * The class {@code AzureAuthConfig} represents a configuration class for the {@link AuthenticationService}.
 *
 * @author Lukas Cerny
 * @version 1.0
 * @since 1.0
 */
public class AzureAuthConfig {

    private final HostConfig host;
    private final String username;
    private final String password;
    private final Optional<Integer> refreshPeriodIfFail;

    /**
     * Constructor sets class attributes from input configuration class {@link PropertyConfig}.
     * @param config - configuration
     */
    public AzureAuthConfig(PropertyConfig config) {
        this.host = new HostConfig(config.getPropertyConfig("host"));
        this.username = config.getStringProperty("username");
        this.password = config.getStringProperty("password");
        this.refreshPeriodIfFail = ofNullable(config.getIntegerProperty("refreshPeriodIfFail"));
    }

    public HostConfig getHost() {
        return host;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public Optional<Integer> getRefreshPeriodIfFail() {
        return refreshPeriodIfFail;
    }
}
