package net.brord.plugins.runescape.config;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import net.brord.plugins.runescape.util.TimeUtil;

import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;

/**
 * A template for a main config (or generally called config.yml)<br/>
 * If you want to read values from your config.yml you should create util methods which handle the internal data structure in the config for you.<br/>
 * Generally speaking, so you can forget what the key in the config is called ;)
 * <br/>
 * Project ghastlegionutil<br/>
 * @author Brord
 * @since 21 jun. 2014, 01:24:11
 */
public abstract class MainConfig extends BasicConfig{
	
	/**
	 * 
	 */
	public MainConfig(FileConfiguration config) {
		super("config");
		setConfig(config);
	}
	
	
	/**
	 * @return
	 */
	public String getPrefix() {
		return ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix", "-> &4brokenprefix <-"));
	}
	
	/**
	 * @return
	 */
	public boolean isDebugOn() {
		return getConfig().getBoolean("debug");
	}
	
	/**
	 * @return
	 */
	public Map<String, Object> getListeners() {
		return getConfig().getConfigurationSection("listeners").getValues(false);
	}
	
	/**
	 * 
	 */
	public List<Integer> getBroadCastTimes() {
		List<Integer> times = new LinkedList<Integer>();
		if (!getConfig().contains("broadcasttimes")) return times;
			
		for (String s : getConfig().getStringList("broadcasttimes")){
			int time = TimeUtil.getTimeSeconds(s);
			if (time != -1) times.add(time);
		}
		return times;
	}


	/**
	 * @return
	 */
	public long getSaveTime() {
		return TimeUtil.getTimeMillis(getConfig().getString("savetime", "1m"));
	}
}
