<?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;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\SalesAgentRepository")
 * @ORM\Table(name="sales_agent")
 */

class SalesAgentEntity extends BaseEntity
{

    const GENDER_MALE = 'Male';
    const GENDER_FEMALE = 'Female';

    /**
     * @ORM\Column(name="is_active", type="boolean")
     * @Groups("forAudit")
     */
    protected $isActive;

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

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

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

    /**
     * @ORM\Column(name="full_name", type="string", length=100, nullable=true)
     */
    protected $fullName;

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

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

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

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

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

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

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

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

    /**
     * @ORM\Column(name="rate", type="decimal", precision=12, scale=2, nullable=true)
     */
    protected $rate;

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

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

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

    /**
     * @ORM\OneToMany(targetEntity="AccountUserEntity", mappedBy="salesAgent")
     */
    protected $accountUsers;

    /**
     * @ORM\OneToMany(targetEntity="SalesAgentReferringHealthFacilityEntity", mappedBy="salesAgent", cascade={"remove"})
     */
    protected $referringHealthFacilities;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->referringHealthFacilities = new ArrayCollection();
    }

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

    /**
     * Set updatedAt
     *
     * @ORM\PreUpdate
     */
    public function setUpdatedAtValue()
    {
        parent::setUpdatedAtValue();
        $this->fullName = ucfirst($this->firstName) . ' ' . ucfirst($this->lastName);
    }

    /**
     * Remove the photo from the disk
     *
     * @ORM\PreRemove
     */
    public function removePhoto() {

        $file = $this->getUploadRootDir() . '/' . $this->parsedPhotoDescription;
        if(!empty($this->parsedPhotoDescription) && file_exists($file)) unlink($file);
    }

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

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

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

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

        return 'uploads/provider/photo';
    }

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

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

    /**
     * get photoWebPath
     *
     * @return string
     */
    public function getPhotoWebPath() {

        $parsedDesc = $this->parsedPhotoDescription;
        $file = $this->getUploadRootDir() . '/' . $parsedDesc;

        if(!empty($parsedDesc) && file_exists($file)) {
            return '/' . $this->getUploadDir() . '/' . $parsedDesc;
        } else {
            return '';
        }
    }

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

    /**
     * Set isActive
     *
     * @param boolean $isActive
     *
     * @return SalesAgentEntity
     */
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;

        return $this;
    }

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

    /**
     * Add referringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\SalesAgentReferringHealthFacilityEntity $referringHealthFacility
     *
     * @return SalesAgentEntity
     */
    public function addReferringHealthFacility(\RxConnexionBundle\Entity\SalesAgentReferringHealthFacilityEntity $referringHealthFacility)
    {
        $this->referringHealthFacilities[] = $referringHealthFacility;

        return $this;
    }

    /**
     * Remove referringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\SalesAgentReferringHealthFacilityEntity $referringHealthFacility
     */
    public function removeReferringHealthFacility(\RxConnexionBundle\Entity\SalesAgentReferringHealthFacilityEntity $referringHealthFacility)
    {
        $this->referringHealthFacilities->removeElement($referringHealthFacility);
    }

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

    /**
     * Set firstName
     *
     * @param string $firstName
     *
     * @return SalesAgentEntity
     */
    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;

        return $this;
    }

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

    /**
     * Set middleName
     *
     * @param string $middleName
     *
     * @return SalesAgentEntity
     */
    public function setMiddleName($middleName)
    {
        $this->middleName = $middleName;

        return $this;
    }

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

    /**
     * Set lastName
     *
     * @param string $lastName
     *
     * @return SalesAgentEntity
     */
    public function setLastName($lastName)
    {
        $this->lastName = $lastName;

        return $this;
    }

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

    /**
     * Set fullName
     *
     * @param string $fullName
     *
     * @return SalesAgentEntity
     */
    public function setFullName($fullName)
    {
        $this->fullName = $fullName;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set rate
     *
     * @param string $rate
     *
     * @return SalesAgentEntity
     */
    public function setRate($rate)
    {
        $this->rate = str_replace(',', '', $rate);

        return $this;
    }

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

    /**
     * Set photoDescription
     *
     * @param string $photoDescription
     *
     * @return SalesAgentEntity
     */
    public function setPhotoDescription($photoDescription)
    {
        $this->photoDescription = $photoDescription;

        return $this;
    }

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

    /**
     * Set parsedPhotoDescription
     *
     * @param string $parsedPhotoDescription
     *
     * @return SalesAgentEntity
     */
    public function setParsedPhotoDescription($parsedPhotoDescription)
    {
        $this->parsedPhotoDescription = $parsedPhotoDescription;

        return $this;
    }

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

    /**
     * Add accountUser
     *
     * @param \RxConnexionBundle\Entity\AccountUserEntity $accountUser
     *
     * @return SalesAgentEntity
     */
    public function addAccountUser(\RxConnexionBundle\Entity\AccountUserEntity $accountUser)
    {
        $this->accountUsers[] = $accountUser;

        return $this;
    }

    /**
     * Remove accountUser
     *
     * @param \RxConnexionBundle\Entity\AccountUserEntity $accountUser
     */
    public function removeAccountUser(\RxConnexionBundle\Entity\AccountUserEntity $accountUser)
    {
        $this->accountUsers->removeElement($accountUser);
    }

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

    /**
     * Set gender
     *
     * @param string $gender
     *
     * @return SalesAgentEntity
     */
    public function setGender($gender)
    {
        $this->gender = $gender;

        return $this;
    }

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

    /**
     * Set birthDate
     *
     * @param \DateTime $birthDate
     *
     * @return SalesAgentEntity
     */
    public function setBirthDate($birthDate)
    {
        $this->birthDate = empty($birthDate) ? NULL : new \DateTime($birthDate);

        return $this;
    }

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

    /**
     * Set address
     *
     * @param string $address
     *
     * @return SalesAgentEntity
     */
    public function setAddress($address)
    {
        $this->address = $address;

        return $this;
    }

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

    /**
     * Set mobileNo
     *
     * @param string $mobileNo
     *
     * @return SalesAgentEntity
     */
    public function setMobileNo($mobileNo)
    {
        $this->mobileNo = $mobileNo;

        return $this;
    }

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

    /**
     * Set mobileNoTwo
     *
     * @param string $mobileNoTwo
     *
     * @return SalesAgentEntity
     */
    public function setMobileNoTwo($mobileNoTwo)
    {
        $this->mobileNoTwo = $mobileNoTwo;

        return $this;
    }

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

    /**
     * Set phoneNo
     *
     * @param string $phoneNo
     *
     * @return SalesAgentEntity
     */
    public function setPhoneNo($phoneNo)
    {
        $this->phoneNo = $phoneNo;

        return $this;
    }

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

    /**
     * Set phoneNoTwo
     *
     * @param string $phoneNoTwo
     *
     * @return SalesAgentEntity
     */
    public function setPhoneNoTwo($phoneNoTwo)
    {
        $this->phoneNoTwo = $phoneNoTwo;

        return $this;
    }

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

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

        return $this;
    }

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