package cz.senslog.connector.fetch.fofr;

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

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

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

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

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


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

        ExecutableFetcher<FofrModel> executor = ExecutableFetcher.create(fetcher);
        logger.info("Fetcher executor for {} was created successfully.", FofrFetcher.class.getSimpleName());

        return executor;
    }
}
