<?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\EmailRepository")
 * @ORM\Table(name="email")
 */

class EmailEntity 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="email", type="string")
     * @Groups("forAudit")
     */
    protected $email;

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


    /**
     * 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->email = $data->getEmail();
        }

    }

//    /**
//     * Remove the photo from the disk
//     *
//     * @ORM\PreRemove
//     */
//    public function removeFile() {
//
//        $file = $this->getUploadRootDir() . '/' . $this->parsedDescription;
//        if(!empty($this->parsedDescription) && file_exists($file)) unlink($file);
//    }

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


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

        return base64_encode($this->id);
    }


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

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

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

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

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

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

//    /**
//     * get fileWebPath
//     *
//     * @return string
//     */
//    public function getFileWebPath() {
//
//        $parsedDesc = $this->parsedDescription;
//        $file = $this->getUploadRootDir() . '/' . $parsedDesc;
//
//        if(!empty($parsedDesc) && file_exists($file)) {
//            return '/' . $this->getUploadDir() . '/' . $parsedDesc;
//        } else {
//            return '';
//        }
//    }

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


    /**
     * Set code
     *
     * @param string $code
     *
     * @return EmailEntity
     */
    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 EmailEntity
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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