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

class FaxingOptionConfirmationEntity extends BaseEntity
{

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

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\FaxingOptionEntity", inversedBy="faxingOptionConfirmations")
     * @ORM\JoinColumn(name="faxing_option_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $faxingOption;

    /**
     * @ORM\ManyToOne(targetEntity="FileTypeEntity", inversedBy="faxingOptionConfirmations")
     * @ORM\JoinColumn(name="file_type_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $fileType;

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

    /**
     * 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 uploadDir
     *
     * @return string
     */
    public function getUploadDir() {

        return 'uploads/faxing_option_file/files';
    }

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

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

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

        return $this;
    }

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

    /**
     * Set parsedDescription
     *
     * @param string $parsedDescription
     *
     * @return FaxingOptionConfirmationEntity
     */
    public function setParsedDescription($parsedDescription)
    {
        $this->parsedDescription = $parsedDescription;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set note
     *
     * @param string $note
     *
     * @return FaxingOptionConfirmationEntity
     */
    public function setNote($note)
    {
        $this->note = $note;

        return $this;
    }

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

    /**
     * Set faxingOption
     *
     * @param \RxConnexionBundle\Entity\FaxingOptionEntity $faxingOption
     *
     * @return FaxingOptionConfirmationEntity
     */
    public function setFaxingOption(\RxConnexionBundle\Entity\FaxingOptionEntity $faxingOption = null)
    {
        $this->faxingOption = $faxingOption;

        return $this;
    }

    /**
     * Get faxingOption
     *
     * @return \RxConnexionBundle\Entity\FaxingOptionEntity
     */
    public function getFaxingOption()
    {
        return $this->faxingOption;
    }

    /**
     * Set fileType
     *
     * @param \RxConnexionBundle\Entity\FileTypeEntity $fileType
     *
     * @return FaxingOptionConfirmationEntity
     */
    public function setFileType(\RxConnexionBundle\Entity\FileTypeEntity $fileType = null)
    {
        $this->fileType = $fileType;

        return $this;
    }

    /**
     * Get fileType
     *
     * @return \RxConnexionBundle\Entity\FileTypeEntity
     */
    public function getFileType()
    {
        return $this->fileType;
    }
}
