package cz.senslog.connector.fetch.senslog.telemetry;

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

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

public class SensLogTelemetryConfig {

    private final String baseUrl;
    private final String bearerToken;
    private final LocalDateTime startAt;

    private final int campaignId;
    private final int entityId;
    private final int actionId;

    private final int limit;
    private final int interval;
    private final Set<Long> allowedStations;

    SensLogTelemetryConfig(DefaultConfig defaultConfig) {
        this.baseUrl = defaultConfig.getStringProperty("baseUrl");
        this.bearerToken = defaultConfig.getStringProperty("bearerToken");

        if (defaultConfig.containsProperty("startAt")) {
            String startAtString = defaultConfig.getStringProperty("startAt");
            this.startAt = startAtString.equalsIgnoreCase("now") ? LocalDateTime.now() : defaultConfig.getLocalDateTimeProperty("startAt");
        } else {
            this.startAt = null;
        }
        this.campaignId = defaultConfig.getIntegerProperty("campaignId");
        this.entityId = defaultConfig.getIntegerProperty("entityId");
        this.actionId = defaultConfig.getIntegerProperty("actionId");
        this.limit = defaultConfig.getIntegerProperty("limit");
        this.interval = defaultConfig.getIntegerProperty("interval");
        if (defaultConfig.containsProperty("allowedStations")) {
            this.allowedStations = defaultConfig.getSetProperty("allowedStations", Long.class);
        } else {
            this.allowedStations = Collections.emptySet();
        }
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public LocalDateTime getStartAt() {
        return startAt;
    }

    public String getBearerToken() {
        return bearerToken;
    }

    public int getLimit() {
        return limit;
    }

    public int getCampaignId() {
        return campaignId;
    }

    public int getEntityId() {
        return entityId;
    }

    public int getActionId() {
        return actionId;
    }

    public int getInterval() {
        return interval;
    }

    public Set<Long> getAllowedStations() {
        return allowedStations;
    }
}
