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

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

    /**
     * @ORM\ManyToOne(targetEntity="ChartTypeEntity", inversedBy="appointmentTargets")
     * @ORM\JoinColumn(name="chart_type_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $chartType;

    /**
     * @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->target = $data->getTarget();
            $this->chartType = $data->getChartType();
        }

    }

//    /**
//     * 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 target
     *
     * @param string $target
     *
     * @return AppointmentTargetEntity
     */
    public function setTarget($target)
    {
        $this->target = $target;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set chartType
     *
     * @param \RxConnexionBundle\Entity\ChartTypeEntity $chartType
     *
     * @return AppointmentTargetEntity
     */
    public function setChartType(\RxConnexionBundle\Entity\ChartTypeEntity $chartType = null)
    {
        $this->chartType = $chartType;

        return $this;
    }

    /**
     * Get chartType
     *
     * @return \RxConnexionBundle\Entity\ChartTypeEntity
     */
    public function getChartType()
    {
        return $this->chartType;
    }
}
