package cz.senslog.connector.push.telemetry;

import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.model.telemetry.TelemetryModel;
import cz.senslog.connector.push.api.ConnectorPushProvider;
import cz.senslog.connector.push.api.ConnectorPusher;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import static cz.senslog.connector.tools.http.HttpClient.newHttpSSLClient;

public class TelemetryPushProvider implements ConnectorPushProvider {

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

    @Override
    public ConnectorPusher<TelemetryModel> createPusher(DefaultConfig defaultConfig) {

        logger.info("Initialization a new push provider {}.", TelemetryPusher.class);

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

        logger.debug("Creating a new instance of {}.", TelemetryPusher.class);
        TelemetryPusher pusher = new TelemetryPusher(config, newHttpSSLClient());
        logger.info("Pusher for {} was created successfully.", TelemetryPusher.class);

        return pusher;
    }
}
