<?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;
use JMS\Serializer\Annotation\MaxDepth;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\EmailTemplateRepository")
 * @ORM\Table(name="email_template")
 */

class EmailTemplateEntity extends BaseEntity
{
    /**
     * @ORM\Column(name="code", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $code;

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

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

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

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

    /**
     * @ORM\OneToMany(targetEntity="PatientEmailEntity", mappedBy="emailTemplate")
     */
    protected $patientEmails;


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

    public function __construct($data=null)
    {
        if(!is_null($data)) {
            $this->id = $data->getId();
            $this->code = $data->getCode();
            $this->description = $data->getDescription();
            $this->body = $data->getBody();
            $this->company = $data->getCompany();
        }

        $this->patientEmails = new ArrayCollection();

    }

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


    /**
     * Get idEncoded
     *
     * @return string
     */
    public function getIdEncoded() {

        return base64_encode($this->id);
    }

    /**
     * Get birthDateAsString
     *
     * @return string
     */
    public function getBirthDateAsString() {

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

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


    /**
     * Set code
     *
     * @param string $code
     *
     * @return EmailTemplateEntity
     */
    public function setCode($code)
    {
        $this->code = $code;

        return $this;
    }

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

    /**
     * Set description
     *
     * @param string $description
     *
     * @return EmailTemplateEntity
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set company
     *
     * @param \RxConnexionBundle\Entity\CompanyEntity $company
     *
     * @return EmailTemplateEntity
     */
    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;
    }

    /**
     * Add patientEmail
     *
     * @param \RxConnexionBundle\Entity\PatientEmailEntity $patientEmail
     *
     * @return EmailTemplateEntity
     */
    public function addPatientEmail(\RxConnexionBundle\Entity\PatientEmailEntity $patientEmail)
    {
        $this->patientEmails[] = $patientEmail;

        return $this;
    }

    /**
     * Remove patientEmail
     *
     * @param \RxConnexionBundle\Entity\PatientEmailEntity $patientEmail
     */
    public function removePatientEmail(\RxConnexionBundle\Entity\PatientEmailEntity $patientEmail)
    {
        $this->patientEmails->removeElement($patientEmail);
    }

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