<?php

namespace App\Model\Entities\Security;

use App\Model\Entities\BaseEntity;
use App\Model\Entities\CommunitySite;
use App\Model\Entities\Game;
use App\Model\Interfaces\IUserEntity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User extends BaseEntity implements IUserEntity
{
    /** @ORM\Column(type="string") */
    protected $nickname;

    /**
     * @var DateTime
     * @ORM\Column(type="datetime")
     */
    protected $registeredAt;

    /**
     * @var DateTime
     * @ORM\Column(type="datetime")
     */
    protected $lastOnline;

    /**
     * @var ArrayCollection
     * @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
     */
    protected $roles;

    /**
     * @var ArrayCollection
     * @ORM\ManyToMany(targetEntity="App\Model\Entities\Game", mappedBy="teamMembers")
     */
    protected $games;

    /**
     * @var ArrayCollection
     * @ORM\ManyToMany(targetEntity="App\Model\Entities\CommunitySite", mappedBy="members")
     */
    protected $communitySites;

    /**
     * User constructor.
     */
    public function __construct()
    {
        $this->registeredAt = new DateTime();
        $this->lastOnline = new DateTime();
        $this->roles = new ArrayCollection();
        $this->games = new ArrayCollection();
        $this->communitySites = new ArrayCollection();
    }

    /**
     * @return mixed
     */
    public function getNickname()
    {
        return $this->nickname;
    }

    /**
     * @param mixed $nickname
     */
    public function setNickname($nickname)
    {
        $this->nickname = $nickname;
    }

    /**
     * @return DateTime
     */
    public function getRegisteredAt()
    {
        return $this->registeredAt;
    }

    /**
     * @return DateTime
     */
    public function getLastOnline()
    {
        return $this->lastOnline;
    }

    /**
     * @param DateTime $lastOnline
     */
    public function setLastOnline($lastOnline)
    {
        $this->lastOnline = $lastOnline;
    }

    /**
     * @return ArrayCollection
     */
    public function getRoles()
    {
        return $this->roles;
    }

    /**
     * @param Role $role
     */
    public function addRole(Role $role)
    {
        if (!$this->getRoles()->contains($role)) {
            $this->roles->add($role);
        }
    }

    /**
     * @param Role $role
     */
    public function removeRole(Role $role)
    {
        $this->roles->remove($role);
    }

    /**
     * @return Game[]
     */
    public function getGames()
    {
        return $this->games;
    }

    /**
     * @return CommunitySite[]|ArrayCollection
     */
    public function getCommunitySites()
    {
        return $this->communitySites;
    }

}