<?php

namespace RxConnexionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use RxConnexionBundle\Entity\Base\BaseEntity;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use JMS\Serializer\Annotation\Groups;


/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\ChatMessageRepository")
 * @ORM\Table(name="chat_message")
 */

class ChatMessageEntity extends BaseEntity
{


    /**
     * @ORM\ManyToOne(targetEntity="ChatEntity", inversedBy="chatMessages")
     * @ORM\JoinColumn(name="chat_id", referencedColumnName="id")
     */
    protected $chat;

    /**
     * @ORM\ManyToOne(targetEntity="ChatParticipantEntity", inversedBy="chatMessages")
     * @ORM\JoinColumn(name="chat_participant_id", referencedColumnName="id")
     */
    protected $chatParticipant;

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

    /**
     * @ORM\Column(name="is_deleted", type="boolean")
     */
    protected $isDeleted;



    /*--------------------------------------------------------------------------------------------------------*/
    /*					Use Defined Setters and Getters														  */
    /*--------------------------------------------------------------------------------------------------------*/

    /**
     * Set createdAt
     *
     * @ORM\PrePersist
     */
    public function setCreatedAtValue()
    {
        parent::setCreatedAtValue();
        $this->isDeleted = 0;
    }

    /**
     * Get createdAtAsTime
     *
     * @return string
     */
    public function getCreatedAtAsTime() {

        $dttst = new DateTimeToStringTransformer();
        return strtotime($dttst->transform($this->createdAt));
    }

    /*--------------------------------------------------------------------------------------------------------*/
    /*					Setters and Getters																	  */
    /*--------------------------------------------------------------------------------------------------------*/



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

        return $this;
    }

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

    /**
     * Set isDeleted
     *
     * @param boolean $isDeleted
     *
     * @return ChatMessageEntity
     */
    public function setIsDeleted($isDeleted)
    {
        $this->isDeleted = $isDeleted;

        return $this;
    }

    /**
     * Get isDeleted
     *
     * @return boolean
     */
    public function getIsDeleted()
    {
        return $this->isDeleted;
    }

    /**
     * Set chat
     *
     * @param \RxConnexionBundle\Entity\ChatEntity $chat
     *
     * @return ChatMessageEntity
     */
    public function setChat(\RxConnexionBundle\Entity\ChatEntity $chat = null)
    {
        $this->chat = $chat;

        return $this;
    }

    /**
     * Get chat
     *
     * @return \RxConnexionBundle\Entity\ChatEntity
     */
    public function getChat()
    {
        return $this->chat;
    }

    /**
     * Set chatParticipant
     *
     * @param \RxConnexionBundle\Entity\ChatParticipantEntity $chatParticipant
     *
     * @return ChatMessageEntity
     */
    public function setChatParticipant(\RxConnexionBundle\Entity\ChatParticipantEntity $chatParticipant = null)
    {
        $this->chatParticipant = $chatParticipant;

        return $this;
    }

    /**
     * Get chatParticipant
     *
     * @return \RxConnexionBundle\Entity\ChatParticipantEntity
     */
    public function getChatParticipant()
    {
        return $this->chatParticipant;
    }
}
