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

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

import net.mc_pandacraft.java.plugin.pandacraftutils.config.ConfigManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;

public class CommandAliasConfigEntry {
	private final String initialCmd;
	private final String replacement;
	private final List<String> permissions;
	
	public CommandAliasConfigEntry(String init, String repl, String perms) {

		permissions = Collections.unmodifiableList(ConfigManager.splitPermissionsString(perms));

		if (init == null || init.trim().equals(""))
			throw new IllegalArgumentException();
		if (repl == null || repl.trim().equals(""))
			throw new IllegalArgumentException();
		
		initialCmd = init;
		replacement = repl;
	}
	
	
	
	public String getInitialCommand() { return initialCmd; }
	public String getReplacementCommand() { return replacement; }

	
	public boolean hasPlayerPermission(OnlinePlayer op) {
		if (op == null) throw new IllegalArgumentException("le joueur ne doit pas être null");
		if (permissions == null)
			return true;
		
		for (String pe : permissions) {
			if (op.hasPermission(pe)) return true;
		}
		return false;
	}

	
}
