package cz.senslog.connector.push.analytics;

import cz.senslog.connector.model.analytics.AnalyticsModel;
import cz.senslog.connector.model.config.DefaultConfig;
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 ConnectorPushAnalyticsProvider implements ConnectorPushProvider {

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

    @Override
    public ConnectorPusher<AnalyticsModel> createPusher(DefaultConfig defaultConfig) {
        logger.info("Initialization a new push provider {}.", AnalyticsPusher.class);

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

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

        return pusher;
    }
}
