<?php

namespace duel\command;

use pocketmine\command\{Command, CommandSender};
use pocketmine\Player;

use duel\command\subcommand\{Criar, Deletar, Setar, Lista, Entrar, Status};
use duel\Loader;
use pocketmine\utils\Config;

class BoxingCommand extends Command
{
	
	/** @var Loader */
	public $loader;
	
	/** @var array */
	private $subCommands = [];
	
	/** @var array */
	public $data = [];
	
	private $config;
	
	/**
	  * DuelCommand constructor.
	  */
	public function __construct(Loader $loader)
	{
		parent::__construct("boxing", "Plugin of the boxing plugin", "/boxing", ["boxing"]);
        $this->setPermission("cmd.boxing");
		$this->loader = $loader;
		$this->registerSubCommands();
        $this->config = new Config($this->loader->getDataFolder() . 'config.yml', Config::YAML);
	}
	
	/**
	  * @oaram CommandSender $sender
	  * @param string $commandLabel
	  * @param array $args
	  */
	public function execute(CommandSender $sender, $commandLabel, array $args)
	{
		if (!$sender instanceof Player) {
		      $sender->sendMessage('§cNão é possível utilizar no console!');
		      return false;
		}
		if (count($args) < 1) {
			$this->mensagemDefault($sender);
			 return false;
		}
		if (!isset($this->subCommands[$args[0]])) {
			$this->mensagemDefault($sender);
			  return false;
		}
		$this->subCommands[$args[0]]->execute($sender, $args);
		return true;
	}
	
	private function mensagemDefault(Player $player) {
        if ($player->hasPermission("cmd.boxing") || $player->isOp()) {
            $player->sendMessage(" ");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r           §fPlugin ".$this->config->get('Cor_Eventos_Arena')."Boxing");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r           §fMade By: ".$this->config->get('Cor_Eventos_Arena')."From");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r           §fDiscord: ".$this->config->get('Cor_Eventos_Arena')."e");
            $player->sendMessage(" ");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r §fUse: ".$this->config->get('Cor_Eventos_Arena')."/boxing criar <nome>");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r §fUse: ".$this->config->get('Cor_Eventos_Arena')."/boxing deletar <nome>");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r §fUse: ".$this->config->get('Cor_Eventos_Arena')."/boxing setar <lobby|pos1|pos2>");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r §fUse: ".$this->config->get('Cor_Eventos_Arena')."/boxing entrar");
            $player->sendMessage(" ");
        } else {
            $player->sendMessage(" ");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r           §fPlugin ".$this->config->get('Cor_Eventos_Arena')."Boxing");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r           §fMade By: ".$this->config->get('Cor_Eventos_Arena')."From");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r           §fDiscord: ".$this->config->get('Cor_Eventos_Arena')."e");
            $player->sendMessage(" ");
            $player->sendMessage("§l".$this->config->get('Cor_Eventos_Arena')."*§r §fUse: ".$this->config->get('Cor_Eventos_Arena')."/boxing entrar");
            $player->sendMessage(" ");
        }
    }
	
	public function registerSubCommands()
	{
		$this->subCommands['criar'] = new Criar($this);
		$this->subCommands['deletar'] = new Deletar($this);
		$this->subCommands['setar'] = new Setar($this);
		$this->subCommands['entrar'] = new Entrar($this);
	}
}