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

class AccountUserHealthFacilityEntity extends BaseEntity
{
    /**
     * @ORM\Column(name="is_deleted", type="boolean")
     */
    protected $isDeleted;

    /**
     * @ORM\Column(name="start_date", type="datetime")
     * @Groups("forAudit")
     */
    protected $startDate;

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

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

    /**
     * @ORM\ManyToOne(targetEntity="HealthFacilityEntity", inversedBy="accountUserHealthFacilities")
     * @ORM\JoinColumn(name="health_facility_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $healthFacility;

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


    /*--------------------------------------------------------------------------------------------------------*/
    /*					Use Defined Setters and Getters														  */
    /*--------------------------------------------------------------------------------------------------------*/
    /**
     * Get startDateAsString
     *
     * @return string
     */
    public function getStartDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->startDate) ? date('m/d/Y', strtotime($dttst->transform($this->startDate))) : '';
    }
    /**
     * Get endDateAsString
     *
     * @return string
     */
    public function getEndDateAsString() {

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

    /**
     * Get startDateAsTime
     *
     * @return string
     */
    public function getStartDateAsTime() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->startDate) ? strtotime($dttst->transform($this->startDate)) : 0;
    }

    /**
     * Get endDateAsTime
     *
     * @return string
     */
    public function getEndDateAsTime() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->endDate) ? strtotime($dttst->transform($this->endDate)) : 0;
    }

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


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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set salesAgent
     *
     * @param \RxConnexionBundle\Entity\SalesAgentEntity $salesAgent
     *
     * @return SalesAgentReferringHealthFacilityEntity
     */
    public function setSalesAgent(\RxConnexionBundle\Entity\SalesAgentEntity $salesAgent = null)
    {
        $this->salesAgent = $salesAgent;

        return $this;
    }

    /**
     * Get salesAgent
     *
     * @return \RxConnexionBundle\Entity\SalesAgentEntity
     */
    public function getSalesAgent()
    {
        return $this->salesAgent;
    }

    /**
     * Set referringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityEntity $referringHealthFacility
     *
     * @return SalesAgentReferringHealthFacilityEntity
     */
    public function setReferringHealthFacility(\RxConnexionBundle\Entity\ReferringHealthFacilityEntity $referringHealthFacility = null)
    {
        $this->referringHealthFacility = $referringHealthFacility;

        return $this;
    }

    /**
     * Get referringHealthFacility
     *
     * @return \RxConnexionBundle\Entity\ReferringHealthFacilityEntity
     */
    public function getReferringHealthFacility()
    {
        return $this->referringHealthFacility;
    }

    /**
     * Set accountUser
     *
     * @param \RxConnexionBundle\Entity\AccountUserEntity $accountUser
     *
     * @return AccountUserHealthFacilityEntity
     */
    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;
    }

    /**
     * Set healthFacility
     *
     * @param \RxConnexionBundle\Entity\HealthFacilityEntity $healthFacility
     *
     * @return AccountUserHealthFacilityEntity
     */
    public function setHealthFacility(\RxConnexionBundle\Entity\HealthFacilityEntity $healthFacility = null)
    {
        $this->healthFacility = $healthFacility;

        return $this;
    }

    /**
     * Get healthFacility
     *
     * @return \RxConnexionBundle\Entity\HealthFacilityEntity
     */
    public function getHealthFacility()
    {
        return $this->healthFacility;
    }

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

        return $this;
    }

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