package nl.sbdeveloper.themeparkplus.util;

import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ConfigUtil {
    public static String __(String str) {
        return ChatColor.translateAlternateColorCodes('&', str);
    }

    public static List<String> getLore(String path, Map<String, String> vars) {
        ArrayList<String> response = new ArrayList<>();
        for (String str : ThemeParkPlus.getSConfig().getFile().getStringList(path)) {
            for (Map.Entry<String, String> entry : vars.entrySet()) {
                str = str.replaceAll(entry.getKey(), entry.getValue());
            }
            response.add(__(str));
        }
        return response;
    }

    public static String getMessage(String path) {
        return getMessage(path, new HashMap<>());
    }

    public static String getMessage(String path, Map<String, String> vars) {
        String message = ThemeParkPlus.getMessages().getFile().getString(path);
        if (message == null) return "";
        for (Map.Entry<String, String> entry : vars.entrySet()) {
            message = message.replaceAll(entry.getKey(), entry.getValue());
        }
        return __(message);
    }

    public static boolean sendConsole(CommandSender sender) {
        if (sender instanceof ConsoleCommandSender) {
            return ThemeParkPlus.getSConfig().getFile().getBoolean("MessageInConsole");
        } else {
            return true;
        }
    }
}
