package eu.eudat.logic.services.helpers;

import eu.eudat.core.logger.Logger;
import eu.eudat.types.WarningLevel;
import eu.eudat.logic.utilities.interfaces.Applier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ikalyvas on 3/1/2018.
 */
//@Service("loggerService")
public class LoggerServiceImpl implements LoggerService {
    private Logger logger;
    private WarningLevel level;
    private Map<WarningLevel, Applier<Logger, String>> options = new HashMap<>();

    public void setLevel(WarningLevel level) {
        this.level = level;
    }

//    @Autowired
    public LoggerServiceImpl(Logger logger) {
        this.logger = logger;
        this.options.put(WarningLevel.DEBUG, (log, message) -> log.debug(message));
        this.options.put(WarningLevel.INFO, (log, message) -> log.info(message));
        this.options.put(WarningLevel.WARN, (log, message) -> log.warn(message));
        this.options.put(WarningLevel.ERROR, (log, message) -> log.error(message));
    }

    public void log(String message) {
        this.options.get(this.level).apply(logger, message);
    }

    public void log(String message, WarningLevel level) {
        this.options.get(level).apply(logger, message);
    }
}
