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

class MarketingStaffScheduleEntity extends BaseEntity
{
    const START_TIME_PERIOD_AM = 'AM';
    const START_TIME_PERIOD_PM = 'PM';
    const END_TIME_PERIOD_AM = 'AM';
    const END_TIME_PERIOD_PM = 'PM';
    const FAX_COVER_SELECTION_1 = '1';
    const FAX_COVER_SELECTION_2 = '2';
    const FAX_COVER_SELECTION_3 = '3';
    const FAX_COVER_SELECTION_4 = '4';
    const FAX_BODY_SELECTION_1 = '1';
    const FAX_BODY_SELECTION_2 = '2';
    const FAX_BODY_SELECTION_3 = '3';
//    const FAX_BODY_SELECTION_4 = '4';
//    const FAX_BODY_SELECTION_5 = '5';

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

    /**
     * @ORM\Column(name="start_time_hour", type="integer", nullable=true)
     */
    protected $startTimeHour;

    /**
     * @ORM\Column(name="start_time_minute", type="integer", nullable=true)
     */
    protected $startTimeMinute;

    /**
     * @ORM\Column(name="start_time_period", type="string", nullable=true)
     */
    protected $startTimePeriod;

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

    /**
     * @ORM\Column(name="end_time_hour", type="integer", nullable=true)
     */
    protected $endTimeHour;

    /**
     * @ORM\Column(name="end_time_minute", type="integer", nullable=true)
     */
    protected $endTimeMinute;

    /**
     * @ORM\Column(name="end_time_period", type="string", nullable=true)
     */
    protected $endTimePeriod;

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

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

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

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

    /**
     * @ORM\Column(name="fax_cover_selection", type="string", length = 20, nullable=true)
     */
    protected $faxCoverSelection;

    /**
     * @ORM\Column(name="fax_body_selection", type="string", length = 20, nullable=true)
     */
    protected $faxBodySelection;

//    /**
//     * @ORM\ManyToOne(targetEntity="LocationEntity", inversedBy="schedules")
//     * @ORM\JoinColumn(name="location_id", referencedColumnName="id")
//     * @Groups("forAudit")
//     * @MaxDepth(1)
//     */
//    protected $location;

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

    /**
     * @ORM\ManyToOne(targetEntity="PatientEntity", inversedBy="marketingStaffSchedules")
     * @ORM\JoinColumn(name="patient_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patient;

    /**
     * @ORM\ManyToOne(targetEntity="MarketingStaffScheduleStatusEntity", inversedBy="marketingStaffSchedules")
     * @ORM\JoinColumn(name="marketing_staff_schedule_status_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $marketingStaffScheduleStatus;

    /**
     * @ORM\ManyToOne(targetEntity="MarketingStaffEntity", inversedBy="marketingStaffSchedules")
     * @ORM\JoinColumn(name="marketing_staff_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $marketingStaff;

    /**
     * @ORM\ManyToOne(targetEntity="ReferringProviderEntity", inversedBy="marketingStaffSchedules")
     * @ORM\JoinColumn(name="referring_provider_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $referringProvider;

    /**
     * @ORM\ManyToOne(targetEntity="ReferringHealthFacilityEntity", inversedBy="marketingStaffSchedules")
     * @ORM\JoinColumn(name="referring_health_facility_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $referringHealthFacility;

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

    /**
     * @ORM\ManyToOne(targetEntity="NoteTemplateEntity", inversedBy="marketingStaffSchedules")
     * @ORM\JoinColumn(name="note_template_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $noteTemplate;

    /**
     * @ORM\OneToOne(targetEntity="MarketingStaffScheduleRequestEntity", inversedBy="marketingStaffSchedule")
     * @ORM\JoinColumn(name="marketing_staff_schedule_request_id", referencedColumnName="id")
     * @Groups("forAudit")
     */
    protected $marketingStaffScheduleRequest;

    /**
     * @ORM\OneToOne(targetEntity="RxConnexionBundle\Entity\ReferringProviderChartEntity", mappedBy="marketingStaffSchedule", cascade={"remove"})
     */
    protected $referringProviderChart;

    /**
     * @ORM\OneToOne(targetEntity="RxConnexionBundle\Entity\ReferringHealthFacilityChartEntity", mappedBy="marketingStaffSchedule", cascade={"remove"})
     */
    protected $referringHealthFacilityChart;

    /**
     * @ORM\OneToMany(targetEntity="AppointmentNoticeFaxEntity", mappedBy="schedule")
     */
    protected $appointmentNoticeFaxes;

    public function __construct()
    {
        $this->appointmentNoticeFaxes = new ArrayCollection();
    }

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

    /**
     * Set updatedAt
     *
     * @ORM\PreUpdate
     */
    public function setUpdatedAtValue()
    {
        parent::setUpdatedAtValue();
        $this->updateStartEndTime();
    }

    /**
     * Concatenate start and end time
     */
    public function updateStartEndTime() {

        $this->startTime = sprintf('%002d', $this->startTimeHour) . ':' . sprintf('%002d', $this->startTimeMinute) . ' ' . $this->startTimePeriod;
        $this->endTime = sprintf('%002d', $this->endTimeHour) . ':' . sprintf('%002d', $this->endTimeMinute) . ' ' . $this->endTimePeriod;

        return $this;
    }

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

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


    /**
     * Set startTime
     *
     * @param string $startTime
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setStartTime($startTime)
    {
        $this->startTime = $startTime;

        return $this;
    }

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

    /**
     * Set startTimeHour
     *
     * @param integer $startTimeHour
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setStartTimeHour($startTimeHour)
    {
        $this->startTimeHour = $startTimeHour;

        return $this;
    }

    /**
     * Get startTimeHour
     *
     * @return integer
     */
    public function getStartTimeHour()
    {
        return $this->startTimeHour;
    }

    /**
     * Set startTimeMinute
     *
     * @param integer $startTimeMinute
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setStartTimeMinute($startTimeMinute)
    {
        $this->startTimeMinute = $startTimeMinute;

        return $this;
    }

    /**
     * Get startTimeMinute
     *
     * @return integer
     */
    public function getStartTimeMinute()
    {
        return $this->startTimeMinute;
    }

    /**
     * Set startTimePeriod
     *
     * @param string $startTimePeriod
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setStartTimePeriod($startTimePeriod)
    {
        $this->startTimePeriod = $startTimePeriod;

        return $this;
    }

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

    /**
     * Set endTime
     *
     * @param string $endTime
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setEndTime($endTime)
    {
        $this->endTime = $endTime;

        return $this;
    }

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

    /**
     * Set endTimeHour
     *
     * @param integer $endTimeHour
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setEndTimeHour($endTimeHour)
    {
        $this->endTimeHour = $endTimeHour;

        return $this;
    }

    /**
     * Get endTimeHour
     *
     * @return integer
     */
    public function getEndTimeHour()
    {
        return $this->endTimeHour;
    }

    /**
     * Set endTimeMinute
     *
     * @param integer $endTimeMinute
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setEndTimeMinute($endTimeMinute)
    {
        $this->endTimeMinute = $endTimeMinute;

        return $this;
    }

    /**
     * Get endTimeMinute
     *
     * @return integer
     */
    public function getEndTimeMinute()
    {
        return $this->endTimeMinute;
    }

    /**
     * Set endTimePeriod
     *
     * @param string $endTimePeriod
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setEndTimePeriod($endTimePeriod)
    {
        $this->endTimePeriod = $endTimePeriod;

        return $this;
    }

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

    /**
     * Set scheduleDate
     *
     * @param \DateTime $scheduleDate
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setScheduleDate($scheduleDate)
    {
        //$this->scheduleDate = empty($scheduleDate) ? NULL : new \DateTime($scheduleDate);
        $scheduleDateExploded = explode('/', $scheduleDate);
        if((count($scheduleDateExploded) == 3 && !checkdate($scheduleDateExploded[0], $scheduleDateExploded[1], $scheduleDateExploded[2])) || empty($scheduleDate)){
            $this->scheduleDate = NULL;
        }else{
            $this->scheduleDate = new \DateTime($scheduleDate);
        }

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set healthFacility
     *
     * @param \RxConnexionBundle\Entity\HealthFacilityEntity $healthFacility
     *
     * @return MarketingStaffScheduleEntity
     */
    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 patient
     *
     * @param \RxConnexionBundle\Entity\PatientEntity $patient
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setPatient(\RxConnexionBundle\Entity\PatientEntity $patient = null)
    {
        $this->patient = $patient;

        return $this;
    }

    /**
     * Get patient
     *
     * @return \RxConnexionBundle\Entity\PatientEntity
     */
    public function getPatient()
    {
        return $this->patient;
    }

    /**
     * Set chartType
     *
     * @param \RxConnexionBundle\Entity\ChartTypeEntity $chartType
     *
     * @return MarketingStaffScheduleEntity
     */
    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;
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set createdBy
     *
     * @param string $createdBy
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setCreatedBy($createdBy)
    {
        $this->createdBy = $createdBy;

        return $this;
    }

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

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

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

    /**
     * Set updatedBy
     *
     * @param string $updatedBy
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setUpdatedBy($updatedBy)
    {
        $this->updatedBy = $updatedBy;

        return $this;
    }

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

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

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

    /**
     * Set patientChart
     *
     * @param \RxConnexionBundle\Entity\PatientChartEntity $patientChart
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setPatientChart(\RxConnexionBundle\Entity\PatientChartEntity $patientChart = null)
    {
        $this->patientChart = $patientChart;

        return $this;
    }

    /**
     * Get patientChart
     *
     * @return \RxConnexionBundle\Entity\PatientChartEntity
     */
    public function getPatientChart()
    {
        return $this->patientChart;
    }

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

        return $this;
    }

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

    /**
     * Set faxCoverSelection
     *
     * @param string $faxCoverSelection
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setFaxCoverSelection($faxCoverSelection)
    {
        $this->faxCoverSelection = $faxCoverSelection;

        return $this;
    }

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

    /**
     * Set faxBodySelection
     *
     * @param string $faxBodySelection
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setFaxBodySelection($faxBodySelection)
    {
        $this->faxBodySelection = $faxBodySelection;

        return $this;
    }

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

    /**
     * Add appointmentNoticeFax
     *
     * @param \RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $appointmentNoticeFax
     *
     * @return MarketingStaffScheduleEntity
     */
    public function addAppointmentNoticeFax(\RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $appointmentNoticeFax)
    {
        $this->appointmentNoticeFaxes[] = $appointmentNoticeFax;

        return $this;
    }

    /**
     * Remove appointmentNoticeFax
     *
     * @param \RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $appointmentNoticeFax
     */
    public function removeAppointmentNoticeFax(\RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $appointmentNoticeFax)
    {
        $this->appointmentNoticeFaxes->removeElement($appointmentNoticeFax);
    }

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

    /**
     * Set marketingStaffScheduleRequest
     *
     * @param \RxConnexionBundle\Entity\MarketingStaffScheduleRequestEntity $marketingStaffScheduleRequest
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setMarketingStaffScheduleRequest(\RxConnexionBundle\Entity\MarketingStaffScheduleRequestEntity $marketingStaffScheduleRequest = null)
    {
        $this->marketingStaffScheduleRequest = $marketingStaffScheduleRequest;

        return $this;
    }

    /**
     * Get marketingStaffScheduleRequest
     *
     * @return \RxConnexionBundle\Entity\MarketingStaffScheduleRequestEntity
     */
    public function getMarketingStaffScheduleRequest()
    {
        return $this->marketingStaffScheduleRequest;
    }

    /**
     * Set marketingStaff
     *
     * @param \RxConnexionBundle\Entity\MarketingStaffEntity $marketingStaff
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setMarketingStaff(\RxConnexionBundle\Entity\MarketingStaffEntity $marketingStaff = null)
    {
        $this->marketingStaff = $marketingStaff;

        return $this;
    }

    /**
     * Get marketingStaff
     *
     * @return \RxConnexionBundle\Entity\MarketingStaffEntity
     */
    public function getMarketingStaff()
    {
        return $this->marketingStaff;
    }

    /**
     * Set marketingStaffScheduleStatus
     *
     * @param \RxConnexionBundle\Entity\MarketingStaffScheduleStatusEntity $marketingStaffScheduleStatus
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setMarketingStaffScheduleStatus(\RxConnexionBundle\Entity\MarketingStaffScheduleStatusEntity $marketingStaffScheduleStatus = null)
    {
        $this->marketingStaffScheduleStatus = $marketingStaffScheduleStatus;

        return $this;
    }

    /**
     * Get marketingStaffScheduleStatus
     *
     * @return \RxConnexionBundle\Entity\MarketingStaffScheduleStatusEntity
     */
    public function getMarketingStaffScheduleStatus()
    {
        return $this->marketingStaffScheduleStatus;
    }

    /**
     * Set referringProviderChart
     *
     * @param \RxConnexionBundle\Entity\ReferringProviderChartEntity $referringProviderChart
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setReferringProviderChart(\RxConnexionBundle\Entity\ReferringProviderChartEntity $referringProviderChart = null)
    {
        $this->referringProviderChart = $referringProviderChart;

        return $this;
    }

    /**
     * Get referringProviderChart
     *
     * @return \RxConnexionBundle\Entity\ReferringProviderChartEntity
     */
    public function getReferringProviderChart()
    {
        return $this->referringProviderChart;
    }

    /**
     * Set referringHealthFacilityChart
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityChartEntity $referringHealthFacilityChart
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setReferringHealthFacilityChart(\RxConnexionBundle\Entity\ReferringHealthFacilityChartEntity $referringHealthFacilityChart = null)
    {
        $this->referringHealthFacilityChart = $referringHealthFacilityChart;

        return $this;
    }

    /**
     * Get referringHealthFacilityChart
     *
     * @return \RxConnexionBundle\Entity\ReferringHealthFacilityChartEntity
     */
    public function getReferringHealthFacilityChart()
    {
        return $this->referringHealthFacilityChart;
    }

    /**
     * Set referringProvider
     *
     * @param \RxConnexionBundle\Entity\ReferringProviderEntity $referringProvider
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setReferringProvider(\RxConnexionBundle\Entity\ReferringProviderEntity $referringProvider = null)
    {
        $this->referringProvider = $referringProvider;

        return $this;
    }

    /**
     * Get referringProvider
     *
     * @return \RxConnexionBundle\Entity\ReferringProviderEntity
     */
    public function getReferringProvider()
    {
        return $this->referringProvider;
    }

    /**
     * Set referringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityEntity $referringHealthFacility
     *
     * @return MarketingStaffScheduleEntity
     */
    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 contactPerson
     *
     * @param string $contactPerson
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setContactPerson($contactPerson)
    {
        $this->contactPerson = $contactPerson;

        return $this;
    }

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

    /**
     * Set noteTemplate
     *
     * @param \RxConnexionBundle\Entity\NoteTemplateEntity $noteTemplate
     *
     * @return MarketingStaffScheduleEntity
     */
    public function setNoteTemplate(\RxConnexionBundle\Entity\NoteTemplateEntity $noteTemplate = null)
    {
        $this->noteTemplate = $noteTemplate;

        return $this;
    }

    /**
     * Get noteTemplate
     *
     * @return \RxConnexionBundle\Entity\NoteTemplateEntity
     */
    public function getNoteTemplate()
    {
        return $this->noteTemplate;
    }
}
