<?php

namespace RxConnexionBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
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\PatientEmailRepository")
 * @ORM\Table(name="patient_email")
 */

class PatientEmailEntity extends BaseEntity
{
    const PATIENT_EMAIL_STATUS_PENDING = 'Pending';
    const PATIENT_EMAIL_STATUS_SENT = 'Sent';

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

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="PatientEntity", inversedBy="patientEmails")
     * @ORM\JoinColumn(name="patient_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patient;

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

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

    /**
     * @ORM\ManyToOne(targetEntity="AccountUserEntity", inversedBy="patientEmails")
     * @ORM\JoinColumn(name="account_user_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $accountUser;

    /**
     * @ORM\ManyToOne(targetEntity="EmailTemplateEntity", inversedBy="patientEmails")
     * @ORM\JoinColumn(name="email_template_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $emailTemplate;

    /**
     * @ORM\OneToMany(targetEntity="PatientEmailCcEntity", mappedBy="patientEmail", orphanRemoval=true, cascade={"persist", "remove"})
     */
    protected $patientEmailCcs;

    /**
     * @ORM\OneToMany(targetEntity="PatientEmailFileEntity", mappedBy="patientEmail", orphanRemoval=true, cascade={"persist", "remove"})
     */
    protected $patientEmailFiles;

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

    public function __construct()
    {
        $this->patientEmailCcs = new ArrayCollection();
        $this->patientEmailFiles = new ArrayCollection();
    }

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


    /**
     * Get uploadRootDir
     *
     * @return string
     */
    public function getTmpRootDir() {

        return __DIR__ . '/../../../web/uploads/patient/emails/tmp';
    }

    /**
     * Get uploadRootDir
     *
     * @return string
     */
    public function getTmpRootDir2() {

        return '/../../../uploads/patient/emails/tmp';
    }

    /**
     * Get uploadDir
     *
     * @return string
     */
    public function getUploadDir() {

        return 'uploads/patient/emails/photo';
    }

    /**
     * Get uploadRootDir
     *
     * @return string
     */
    public function getUploadRootDir() {

        return __DIR__ . '/../../../web/' . $this->getUploadDir();
    }

    /**
     * Get dateAsString
     *
     * @return string
     */
    public function getDateAsString() {

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

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



    /**
     * Set customBody
     *
     * @param string $customBody
     *
     * @return PatientEmailEntity
     */
    public function setCustomBody($customBody)
    {
        $this->customBody = $customBody;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set date
     *
     * @param \DateTime $date
     *
     * @return PatientEmailEntity
     */
    public function setDate($date)
    {
        $this->date = $date;

        return $this;
    }

    /**
     * Get date
     *
     * @return \DateTime
     */
    public function getDate()
    {
        return $this->date;
    }

    /**
     * Set status
     *
     * @param string $status
     *
     * @return PatientEmailEntity
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

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

    /**
     * Set email
     *
     * @param string $email
     *
     * @return PatientEmailEntity
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

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

    /**
     * Set patient
     *
     * @param \RxConnexionBundle\Entity\PatientEntity $patient
     *
     * @return PatientEmailEntity
     */
    public function setPatient(\RxConnexionBundle\Entity\PatientEntity $patient = null)
    {
        $this->patient = $patient;

        return $this;
    }

    /**
     * Get patient
     *
     * @return \RxConnexionBundle\Entity\PatientEntity
     */
    public function getPatient()
    {
        return $this->patient;
    }

    /**
     * Set accountUser
     *
     * @param \RxConnexionBundle\Entity\AccountUserEntity $accountUser
     *
     * @return PatientEmailEntity
     */
    public function setAccountUser(\RxConnexionBundle\Entity\AccountUserEntity $accountUser = null)
    {
        $this->accountUser = $accountUser;

        return $this;
    }

    /**
     * Get accountUser
     *
     * @return \RxConnexionBundle\Entity\AccountUserEntity
     */
    public function getAccountUser()
    {
        return $this->accountUser;
    }

    /**
     * Add patientEmailCc
     *
     * @param \RxConnexionBundle\Entity\PatientEmailCcEntity $patientEmailCc
     *
     * @return PatientEmailEntity
     */
    public function addPatientEmailCc(\RxConnexionBundle\Entity\PatientEmailCcEntity $patientEmailCc)
    {
        $patientEmailCc->setPatientEmail($this);
        $this->patientEmailCcs[] = $patientEmailCc;

        return $this;
    }

    /**
     * Remove patientEmailCc
     *
     * @param \RxConnexionBundle\Entity\PatientEmailCcEntity $patientEmailCc
     */
    public function removePatientEmailCc(\RxConnexionBundle\Entity\PatientEmailCcEntity $patientEmailCc)
    {
        $this->patientEmailCcs->removeElement($patientEmailCc);
    }

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

    /**
     * Add patientEmailFile
     *
     * @param \RxConnexionBundle\Entity\PatientEmailFileEntity $patientEmailFile
     *
     * @return PatientEmailEntity
     */
    public function addPatientEmailFile(\RxConnexionBundle\Entity\PatientEmailFileEntity $patientEmailFile)
    {
        $this->patientEmailFiles[] = $patientEmailFile;

        return $this;
    }

    /**
     * Remove patientEmailFile
     *
     * @param \RxConnexionBundle\Entity\PatientEmailFileEntity $patientEmailFile
     */
    public function removePatientEmailFile(\RxConnexionBundle\Entity\PatientEmailFileEntity $patientEmailFile)
    {
        $this->patientEmailFiles->removeElement($patientEmailFile);
    }

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

    /**
     * Set emailTemplate
     *
     * @param \RxConnexionBundle\Entity\EmailTemplateEntity $emailTemplate
     *
     * @return PatientEmailEntity
     */
    public function setEmailTemplate(\RxConnexionBundle\Entity\EmailTemplateEntity $emailTemplate = null)
    {
        $this->emailTemplate = $emailTemplate;

        return $this;
    }

    /**
     * Get emailTemplate
     *
     * @return \RxConnexionBundle\Entity\EmailTemplateEntity
     */
    public function getEmailTemplate()
    {
        return $this->emailTemplate;
    }

    /**
     * Set emailFrom
     *
     * @param string $emailFrom
     *
     * @return PatientEmailEntity
     */
    public function setEmailFrom($emailFrom)
    {
        $this->emailFrom = $emailFrom;

        return $this;
    }

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