<?php

namespace RxConnexionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use RxConnexionBundle\Entity\Base\BaseEntity;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\MaxDepth;


/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\TicketRepository")
 * @ORM\Table(name="ticket")
 */

class TicketEntity extends BaseEntity
{

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

    /**
     * @ORM\OneToMany(targetEntity="PatientTicketEntity", mappedBy="ticket", orphanRemoval=true, cascade={"persist", "remove"})
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patientTickets;

    /**
     * @ORM\OneToMany(targetEntity="PatientChartTicketEntity", mappedBy="ticket", orphanRemoval=true, cascade={"persist", "remove"})
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patientChartTickets;

    /**
     * @ORM\OneToMany(targetEntity="TicketCcEntity", mappedBy="ticket", orphanRemoval=true, cascade={"persist", "remove"})
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $ticketCcs;

    /**
     * @ORM\OneToMany(targetEntity="TicketNoteEntity", mappedBy="ticket", orphanRemoval=true, cascade={"persist", "remove"})
     * @ORM\OrderBy({"createdAt" : "DESC"})
     */
    protected $ticketNotes;

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

    /**
     * @ORM\ManyToOne(targetEntity="TicketStatusEntity", inversedBy="tickets")
     * @ORM\JoinColumn(name="ticket_status_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $ticketStatus;

    /**
     * @ORM\ManyToOne(targetEntity="TicketSeverityEntity", inversedBy="tickets")
     * @ORM\JoinColumn(name="ticket_severity_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $ticketSeverity;

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

    public function __construct()
    {
        $this->patientTickets = new ArrayCollection();
        $this->patientChartTickets = new ArrayCollection();
        $this->ticketCcs = new ArrayCollection();
    }


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

    /**
     * Get LatestTicketNote
     *
     * @return TicketNoteEntity
     */
    public function getLatestTicketNote()
    {
        foreach($this->getTicketNotes() as $ticketNote){
            return $ticketNote;
        }
    }

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


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

        return $this;
    }

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

    /**
     * Add patientTicket
     *
     * @param \RxConnexionBundle\Entity\PatientTicketEntity $patientTicket
     *
     * @return TicketEntity
     */
    public function addPatientTicket(\RxConnexionBundle\Entity\PatientTicketEntity $patientTicket)
    {
        $patientTicket->setTicket($this);
        $this->patientTickets[] = $patientTicket;

        return $this;
    }

    /**
     * Remove patientTicket
     *
     * @param \RxConnexionBundle\Entity\PatientTicketEntity $patientTicket
     */
    public function removePatientTicket(\RxConnexionBundle\Entity\PatientTicketEntity $patientTicket)
    {
        $this->patientTickets->removeElement($patientTicket);
    }

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

    /**
     * Add patientChartTicket
     *
     * @param \RxConnexionBundle\Entity\PatientChartTicketEntity $patientChartTicket
     *
     * @return TicketEntity
     */
    public function addPatientChartTicket(\RxConnexionBundle\Entity\PatientChartTicketEntity $patientChartTicket)
    {
        $patientChartTicket->setTicket($this);
        $this->patientChartTickets[] = $patientChartTicket;

        return $this;
    }

    /**
     * Remove patientChartTicket
     *
     * @param \RxConnexionBundle\Entity\PatientChartTicketEntity $patientChartTicket
     */
    public function removePatientChartTicket(\RxConnexionBundle\Entity\PatientChartTicketEntity $patientChartTicket)
    {
        $this->patientChartTickets->removeElement($patientChartTicket);
    }

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

    /**
     * Set accountUser
     *
     * @param \RxConnexionBundle\Entity\AccountUserEntity $accountUser
     *
     * @return TicketEntity
     */
    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 ticketStatus
     *
     * @param \RxConnexionBundle\Entity\TicketStatusEntity $ticketStatus
     *
     * @return TicketEntity
     */
    public function setTicketStatus(\RxConnexionBundle\Entity\TicketStatusEntity $ticketStatus = null)
    {
        $this->ticketStatus = $ticketStatus;

        return $this;
    }

    /**
     * Get ticketStatus
     *
     * @return \RxConnexionBundle\Entity\TicketStatusEntity
     */
    public function getTicketStatus()
    {
        return $this->ticketStatus;
    }

    /**
     * Add ticketNote
     *
     * @param \RxConnexionBundle\Entity\TicketNoteEntity $ticketNote
     *
     * @return TicketEntity
     */
    public function addTicketNote(\RxConnexionBundle\Entity\TicketNoteEntity $ticketNote)
    {
        $this->ticketNotes[] = $ticketNote;

        return $this;
    }

    /**
     * Remove ticketNote
     *
     * @param \RxConnexionBundle\Entity\TicketNoteEntity $ticketNote
     */
    public function removeTicketNote(\RxConnexionBundle\Entity\TicketNoteEntity $ticketNote)
    {
        $this->ticketNotes->removeElement($ticketNote);
    }

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

    /**
     * Set ticketSeverity
     *
     * @param \RxConnexionBundle\Entity\TicketSeverityEntity $ticketSeverity
     *
     * @return TicketEntity
     */
    public function setTicketSeverity(\RxConnexionBundle\Entity\TicketSeverityEntity $ticketSeverity = null)
    {
        $this->ticketSeverity = $ticketSeverity;

        return $this;
    }

    /**
     * Get ticketSeverity
     *
     * @return \RxConnexionBundle\Entity\TicketSeverityEntity
     */
    public function getTicketSeverity()
    {
        return $this->ticketSeverity;
    }

    /**
     * Add ticketCc
     *
     * @param \RxConnexionBundle\Entity\TicketCcEntity $ticketCc
     *
     * @return TicketEntity
     */
    public function addTicketCc(\RxConnexionBundle\Entity\TicketCcEntity $ticketCc)
    {
        $ticketCc->setTicket($this);
        $this->ticketCcs[] = $ticketCc;

        return $this;
    }

    /**
     * Remove ticketCc
     *
     * @param \RxConnexionBundle\Entity\TicketCcEntity $ticketCc
     */
    public function removeTicketCc(\RxConnexionBundle\Entity\TicketCcEntity $ticketCc)
    {
        $this->ticketCcs->removeElement($ticketCc);
    }

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