package cz.senslog.fetch.senslog.telemetry;

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

import java.time.LocalDateTime;

public class SensLogTelemetryConfig {

    private final String baseUrl;
    private final String bearerToken;
    private final LocalDateTime startAt;
    private final int campaignId;
    private final int limit;
    private final int interval;

    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.limit = defaultConfig.getIntegerProperty("limit");
        this.interval = defaultConfig.getIntegerProperty("interval");
    }

    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 getInterval() {
        return interval;
    }
}
