package cz.senslog.connector.fetch.drutes;

import cz.senslog.connector.fetch.api.ConnectorFetchProvider;
import cz.senslog.connector.fetch.api.ConnectorFetcher;
import cz.senslog.connector.fetch.api.ExecutableFetcher;
import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.model.drutes.DrutesModel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


public final class ConnectorFetchDrutesProvider implements ConnectorFetchProvider {

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

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

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

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

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

        return executor;
    }
}
