<?php

namespace App\Model\Entities\Components;

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

/**
 * @ORM\Entity
 * @ORM\Table(name="post")
 */
class Post extends BaseRecord
{
    const SUBMITTED = 'submitted';

    /**
     * @ORM\Column(type="text")
     */
    protected $title;

    /**
     * @ORM\Column(type="text")
     */
    protected $message;

    /**
     * @var IMessenger
     * @ORM\ManyToOne(targetEntity="Messenger")
     */
    protected $messenger;

    /**
     * @var Post
     * @ORM\ManyToOne(targetEntity="Post", inversedBy="replies")
     * @ORM\JoinColumn(nullable=true)
     */
    protected $reply;

    /**
     * @var ArrayCollection
     * @ORM\OneToMany(targetEntity="Post", mappedBy="reply")
     */
    protected $replies;

    public function __construct(User $createdBy)
    {
        parent::__construct($createdBy);
        $this->setState(self::SUBMITTED);
    }


    /**
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * @param string $title
     */
    public function setTitle($title)
    {
        $this->title = $title;
    }

    /**
     * @return string
     */
    public function getMessage()
    {
        return $this->message;
    }

    /**
     * @param string $message
     */
    public function setMessage($message)
    {
        $this->message = $message;
    }

    /**
     * @return IMessenger
     */
    public function getMessenger() : IMessenger
    {
        return $this->messenger;
    }

    /**
     * @param IMessenger $messenger
     */
    public function setMessenger(IMessenger $messenger)
    {
        $this->messenger = $messenger;
    }

    /**
     * @return Post
     */
    public function getReply()
    {
        return $this->reply;
    }

    /**
     * @param Post $reply
     */
    public function setReply($reply)
    {
        $this->reply = $reply;
    }

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

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


}