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

class LoginTrackerEntity extends BaseEntity
{
    const STATUS_LOGIN = 'User Login';
    const STATUS_LOGOUT = 'User Logout';
    const STATUS_DISCONNECTED = 'User Disconnected';

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

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

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

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

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

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

    public function __construct()
    {

    }

    /*--------------------------------------------------------------------------------------------------------*/
    /*					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))) : '';
//    }
    /*--------------------------------------------------------------------------------------------------------*/
    /*					Setters and Getters																	  */
    /*--------------------------------------------------------------------------------------------------------*/




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

        return $this;
    }

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

    /**
     * Set startDate
     *
     * @param \DateTime $startDate
     *
     * @return LoginTrackerEntity
     */
    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 LoginTrackerEntity
//     */
//    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 note
     *
     * @param string $note
     *
     * @return LoginTrackerEntity
     */
    public function setNote($note)
    {
        $this->note = $note;

        return $this;
    }

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

    /**
     * Set accountUser
     *
     * @param \RxConnexionBundle\Entity\AccountUserEntity $accountUser
     *
     * @return LoginTrackerEntity
     */
    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 username
     *
     * @param string $username
     *
     * @return LoginTrackerEntity
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

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