package cz.senslog.connector.fetch.metno;

import cz.senslog.connector.fetch.api.ConnectorFetchProvider;
import cz.senslog.connector.fetch.api.ExecutableFetcher;
import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.model.metno.MetnoModel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

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

public class ConnectorFetchMetnoProvider implements ConnectorFetchProvider {

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

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

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


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

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

        return executor;
    }
}
