package cz.senslog.connector.push.rest.senslog.v1;

import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.model.v1.SenslogV1Model;
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.newHttpClient;

/**
 * The class {@code SenslogV1ConnectorPushProvider} represents a concrete implementation of {@link ConnectorPushProvider}.
 * Contains basic functionality to configure implementation of {@link ConnectorPusher} from the default configuration.
 *
 * @author Lukas Cerny
 * @version 1.0
 * @since 1.0
 */
public final class
SenslogV1ConnectorPushProvider implements ConnectorPushProvider {

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

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

        logger.debug("Creating a new configuration.");
        SenslogV1Config senslogConfig = new SenslogV1Config(config);
        logger.info("Configuration for {} was created successfully.", SenslogV1Pusher.class);

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

        return pusher;
    }
}
