package cz.senslog.fetch.senslog.telemetry;

import cz.senslog.connector.fetch.api.ExecutableFetcher;
import cz.senslog.connector.model.api.GeoJsonModel;
import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.tools.http.HttpClient;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ConnectorFetchSenslogTelemetryProvider implements cz.senslog.connector.fetch.api.ConnectorFetchProvider {

    private static final Logger logger = LogManager.getLogger(ConnectorFetchSenslogTelemetryProvider.class);

    @Override
    public ExecutableFetcher<GeoJsonModel> createExecutableFetcher(DefaultConfig defaultConfig) {
        logger.info("Initialization a new fetch provider {}.", ConnectorFetchSenslogTelemetryProvider.class.getSimpleName());

        logger.debug("Creating a new configuration.");
        SensLogTelemetryConfig config = new SensLogTelemetryConfig(defaultConfig);
        logger.info("Configuration for {} was created successfully.", SensLogTelemetryFetcher.class.getSimpleName());


        logger.debug("Creating a new instance of {}.", SensLogTelemetryFetcher.class);
        SensLogTelemetryFetcher fetcher = new SensLogTelemetryFetcher(config, HttpClient.newHttpSSLClient());
        logger.info("Fetcher for {} was created successfully.", SensLogTelemetryFetcher.class.getSimpleName());

        logger.debug("Creating a new instance of {}.", SensLogTelemetryProxySession.class);
        ExecutableFetcher<GeoJsonModel> executor = ExecutableFetcher.createWithProxySession(new SensLogTelemetryProxySession(fetcher));
        logger.info("Fetcher executor for {} was created successfully.", SensLogTelemetryFetcher.class.getSimpleName());

        return executor;
    }
}