<?php

namespace RxConnexionBundle\Entity;

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

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\LetterTemplateRepository")
 * @ORM\Table(name="letter_template")
 */

class LetterTemplateEntity extends BaseEntity
{
    /**
     * @ORM\Column(name="is_deleted", type="boolean")
     */
    protected $isDeleted;

    /**
     * @ORM\Column(name="letter_type", type="string")
     * @Groups("forAudit")
     */
    protected $letterType;

    /**
     * @ORM\Column(name="fax_cover_body", type="text", nullable=true)
     * @Groups("forAudit")
     */
    protected $faxCoverBody;

    /**
     * @ORM\Column(name="email_body", type="text", nullable=true)
     * @Groups("forAudit")
     */
    protected $emailBody;

    /**
     * @ORM\Column(name="body", type="text", nullable=true)
     * @Groups("forAudit")
     */
    protected $body;

    /**
     * @ORM\ManyToOne(targetEntity="CompanyEntity", inversedBy="letterTemplates")
     * @ORM\JoinColumn(name="company_id", referencedColumnName="id")
     * @Groups("forAudit")
     */
    protected $company;

    /**
     * @ORM\OneToMany(targetEntity="LetterTemplateEmailEntity", mappedBy="letterTemplate", orphanRemoval=true, cascade={"persist", "remove"})
     */
    protected $letterTemplateEmails;

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

    /*--------------------------------------------------------------------------------------------------------*/
    /*					User Defined Setters and Getters													  */
    /*--------------------------------------------------------------------------------------------------------*/

    /**
     * Get startDateAsString
     *
     * @return string
     */
    public function getStartDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->startDate) ? date('m/d/Y', strtotime($dttst->transform($this->startDate))) : '';
    }

    /**
     * Get endDateAsString
     *
     * @return string
     */
    public function getEndDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->endDate) ? date('m/d/Y', strtotime($dttst->transform($this->endDate))) : '';
    }

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


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

        return $this;
    }

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

    /**
     * Set letterType
     *
     * @param string $letterType
     *
     * @return LetterTemplateEntity
     */
    public function setLetterType($letterType)
    {
        $this->letterType = $letterType;

        return $this;
    }

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

    /**
     * Set faxCoverBody
     *
     * @param string $faxCoverBody
     *
     * @return LetterTemplateEntity
     */
    public function setFaxCoverBody($faxCoverBody)
    {
        $this->faxCoverBody = $faxCoverBody;

        return $this;
    }

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

    /**
     * Set body
     *
     * @param string $body
     *
     * @return LetterTemplateEntity
     */
    public function setBody($body)
    {
        $this->body = $body;

        return $this;
    }

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

    /**
     * Set company
     *
     * @param \RxConnexionBundle\Entity\CompanyEntity $company
     *
     * @return LetterTemplateEntity
     */
    public function setCompany(\RxConnexionBundle\Entity\CompanyEntity $company = null)
    {
        $this->company = $company;

        return $this;
    }

    /**
     * Get company
     *
     * @return \RxConnexionBundle\Entity\CompanyEntity
     */
    public function getCompany()
    {
        return $this->company;
    }
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->letterTemplateEmails = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add letterTemplateEmail
     *
     * @param \RxConnexionBundle\Entity\LetterTemplateEmailEntity $letterTemplateEmail
     *
     * @return LetterTemplateEntity
     */
    public function addLetterTemplateEmail(\RxConnexionBundle\Entity\LetterTemplateEmailEntity $letterTemplateEmail)
    {
        $letterTemplateEmail->setLetterTemplate($this);
        $this->letterTemplateEmails[] = $letterTemplateEmail;

        return $this;
    }

    /**
     * Remove letterTemplateEmail
     *
     * @param \RxConnexionBundle\Entity\LetterTemplateEmailEntity $letterTemplateEmail
     */
    public function removeLetterTemplateEmail(\RxConnexionBundle\Entity\LetterTemplateEmailEntity $letterTemplateEmail)
    {
        $this->letterTemplateEmails->removeElement($letterTemplateEmail);
    }

    /**
     * Get letterTemplateEmails
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getLetterTemplateEmails()
    {
        return $this->letterTemplateEmails;
    }

    /**
     * Set emailBody
     *
     * @param string $emailBody
     *
     * @return LetterTemplateEntity
     */
    public function setEmailBody($emailBody)
    {
        $this->emailBody = $emailBody;

        return $this;
    }

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