<?php

namespace bedwars\util;

use pocketmine\Player;

class Team {

    /** @var array */
    private $players = array();
    
    /** @var array */
    private $necPlayers = array();
    
    /** @var bool */
    public $isAlive = true;
    
    /** @var string */
    public $team;
    
    /** @var Time() */
    private $trap = null;

    /**
    * @param string $team
    */
    public function __construct(string $team) {
        $this->team = $team;
    }
    
    /** 
     * @return array
     */
    public function getPlayers() : array {
        return $this->players;
    }
    
    
    /** 
     * @return string
     */
    public function getName() : string {
        return $this->team;
    }
    
    /**
     * @return int
     */
    public function getCount() : int {
        return count($this->players);
    }
    
    /**
     * @return int
     */
    public function getNecCount() : int {
        return count($this->necPlayers);
    }
    
    /**
     * @return bool
     */
    public function isAlive() : bool {
        return $this->isAlive;
    }
    
    /**
     * @param Player $player
     */
    public function addPlayer(Player $player) {
        $this->players[$player->getName()] = $player;
        $this->necPlayers[$player->getName()] = $player;
    }
    
    /**
     * @param return bool
     */
    public function issetPlayer(string $name) : bool {
        return isset($this->players[$name]);
    }
    
    /**
     * @param Player $player
     */
    public function removePlayer(Player $player) : bool {
        if ($this->issetPlayer($player->getName())) {
            unset($this->players[$player->getName()]);
            unset($this->necPlayers[$player->getName()]);
            return true;
        }
        return false;
    }
    
    /**
     * @param Player $player
     */
    public function removeNecPlayer(Player $player) : bool {
        unset($this->necPlayers[$player->getName()]);
        return false;
    }
    
    /**
     * @return bool
     */
    public function canUseTrap() : bool {
        if ($this->trap != null) {
            if ((time() - $this->trap) >= 180)  {
                return true;
            } else {
                return false;
            }
            echo "" . ($this->trap - time());
        } else {
            return true;
        }
    }
    
    /**
     * @param int $level
     */
    public function useTrap(int $level) {
        $this->trap = time();
    }
}
?>