<?php

namespace App\Model\Entities\Components\Forum;

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

/**
 * @ORM\Entity
 */
class Topic extends Messenger
{
    const ACTIVE = 'active';

    /**
     * @var Forum
     * @ORM\ManyToOne(targetEntity="Forum", inversedBy="topics")
     */
    protected $forum;

    /**
     * @var Post[] | ArrayCollection
     * @ORM\OneToMany(targetEntity="App\Model\Entities\Components\Post", mappedBy="messenger")
     */
    protected $posts;

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

        $this->forum = $forum;
        $this->posts = new ArrayCollection();
        $this->setState(self::ACTIVE);
    }

    /**
     * @return Forum
     */
    public function getForum()
    {
        return $this->forum;
    }

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

    protected function getValidStates() : array
    {
        $states =  parent::getValidStates();
        $states[] = self::ACTIVE;

        return $states;
    }


}