<?php

namespace App\Model\Entities;

use App\Model\Entities\Security\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class CommunitySite extends PortalSite
{
    /**
     * @var Game
     * @ORM\ManyToOne(targetEntity="Game")
     */
    protected $game;

    /**
     * @var ArrayCollection
     * @ORM\ManyToMany(targetEntity="App\Model\Entities\Security\User", inversedBy="communitySites")
     * @ORM\JoinTable(name="members")
     */
    protected $members;

    public function __construct(User $createdBy)
    {
        parent::__construct($createdBy);

        $this->members = new ArrayCollection();
    }

    /**
     * @return Game
     */
    public function getGame() : Game
    {
        return $this->game;
    }

    /**
     * @param Game $game
     */
    public function setGame(Game $game)
    {
        $this->game = $game;
    }

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

    public function addMember(User $user)
    {
        if (!$this->members->contains($user)) {
            $this->members->add($user);
        }
    }

    public function removeMember(User $user)
    {
        $this->members->remove($user);
    }
}