package net.mc_pandacraft.java.plugin.pandacraftutils.config;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

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

import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;

public class DefaultConfig {
	private PandacraftUtils plugin = PandacraftUtils.getInstance();
	

	private FileConfiguration configFile;
	
	
	
	
	
	
	

	
	
	/*
	 * Connexion à la base de donnée
	 */
	
	public final String database_host;
	public final int    database_port;
	public final String database_user;
	public final String database_base;
	public final String database_pass;

	/*
	 * Configuration AFK
	 */
	/** En secondes */
	public final int afk_timeoutAutoMessage;
	/** En secondes */
	public final int afk_timeoutAutoKick;

	/*
	 * Configuration analyse du chat et des messages privés
	 * (antispam, insultes, publicité)
	 */
	/** En milisecondes */
	public final long chatAnalysis_timeBeforeResendSameMessage;
	/** En milisecondes */
	public final long chatAnalysis_timeBeforeResendSameCommand;
	/** En milisecondes */
	public final long chatAnalysis_timePerCaracterForNewMessage;
	public final int  chatAnalysis_maxViolationLevel;
	public final int  chatAnalysis_nbSecondForOneVLDown;
	
	/*
	 * Cubos
	 */
	public final List<String> cubos_worlds;
	
	/*
	 * Users cleaner
	 */
	public final String cleaner_usersCleanerGroup;
	
	/*
	 * Automessages
	 */
	/** En seconde : pour les joueurs != visiteur */
	public final int autoMessages_playerInterval;
	/** En seconde : pour les visiteurs */
	public final int autoMessages_defaultInterval;
	
	/*
	 * Server Messages
	 */
	public final String serverMessages_defaultColor;
	public final String serverMessages_prefix;
	
	/*
	 * Ping MOTD
	 */
	public final String pingMOTD;
	
	/*
	 * Entity Spam
	 */
	public final List<String> entitySpam_worlds;
	public final int entitySpam_limitPerChunk;
	
	/*
	 * Network API
	 */
	public final String networkAPI_pass;
	
	
	
	
	
	
	
	
	
	DefaultConfig() {
		plugin.reloadConfig();
		
		plugin.saveDefaultConfig();
		
		configFile = plugin.getConfig();
		
		
		database_host = configFile.getString("database.host");
		database_port = configFile.getInt("database.port");
		database_base = configFile.getString("database.base");
		database_user = configFile.getString("database.user");
		database_pass = configFile.getString("database.pass");
		
		
		afk_timeoutAutoMessage = configFile.getInt("afk.timeoutAutoMessage");
		afk_timeoutAutoKick = configFile.getInt("afk.timeoutAutoKick");
		
		
		chatAnalysis_timeBeforeResendSameMessage = configFile.getLong("chatAnalysis.timeBeforeResendSameMessage");
		chatAnalysis_timeBeforeResendSameCommand = configFile.getLong("chatAnalysis.timeBeforeResendSameCommand");
		chatAnalysis_timePerCaracterForNewMessage = configFile.getLong("chatAnalysis.timePerCaracterForNewMessage");
		chatAnalysis_maxViolationLevel = configFile.getInt("chatAnalysis.maxViolationLevel");
		chatAnalysis_nbSecondForOneVLDown = configFile.getInt("chatAnalysis.nbSecondForOneVLDown");
		
		
		cubos_worlds = getSplittedString("cubos.worlds", ";");

		
		cleaner_usersCleanerGroup = configFile.getString("cleaner.usersCleanerGroup");
		
		
		autoMessages_playerInterval = configFile.getInt("autoMessages.playerInterval");
		autoMessages_defaultInterval = configFile.getInt("autoMessages.defaultInterval");
		

		serverMessages_defaultColor = getTransletedColorCode("serverMessages.defaultColor");
		serverMessages_prefix = getTransletedColorCode("serverMessages.prefix");
		
		
		pingMOTD = getTransletedColorCode("pingMOTD").replace("\\n", "\n");
		
		
		entitySpam_worlds = getSplittedString("entitySpam.worlds", ";");
		entitySpam_limitPerChunk = configFile.getInt("entitySpam.limitPerChunk");
		
		
		networkAPI_pass = configFile.getString("networkAPI.pass");
		
		
	}
	
	
	
	
	
	

	
	private List<String> getSplittedString(String path, String split) {
		String value = configFile.getString(path, "");
		
		return Collections.unmodifiableList(Arrays.asList(value.split(split)));
	}
	
	private String getTransletedColorCode(String path) {
		return ChatColor.translateAlternateColorCodes('&', configFile.getString(path, ""));
	}
}
