<?php

namespace RxConnexionBundle\Entity;

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

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\BranchRepository")
 * @ORM\Table(name="branch", indexes={@ORM\Index(name="IDX_SEARCH_000", columns={"description"})})
 */

class BranchEntity extends BaseEntity
{

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

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

    /**
     * @ORM\Column(type="string")
     */
    protected $description;

    /**
     * @ORM\ManyToOne(targetEntity="CompanyEntity", inversedBy="branches")
     * @ORM\JoinColumn(name="company_id", referencedColumnName="id")
     * @MaxDepth(1)
     */
    protected $company;

    /**
     * @ORM\OneToMany(targetEntity="AccountUserBranchEntity", mappedBy="branch")
     */
    protected $accountUserBranches;


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

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


    /*--------------------------------------------------------------------------------------------------------*/
    /*					User Defined Setters and Getters													  */
    /*--------------------------------------------------------------------------------------------------------*/

    /**
     * Get companyAndDescription
     *
     * @return string
     */
    public function getCompanyAndDescription() {

        return ($this->company ? $this->company->getAccountAndDescription() . ' | ' : '') . $this->description;
    }

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


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

        return $this;
    }

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

    /**
     * Set code
     *
     * @param string $code
     *
     * @return BranchEntity
     */
    public function setCode($code)
    {
        $this->code = $code;

        return $this;
    }

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

    /**
     * Set description
     *
     * @param string $description
     *
     * @return BranchEntity
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

    /**
     * Set company
     *
     * @param \RxConnexionBundle\Entity\CompanyEntity $company
     *
     * @return BranchEntity
     */
    public function setCompany(\RxConnexionBundle\Entity\CompanyEntity $company = null)
    {
        $this->company = $company;

        return $this;
    }

    /**
     * Get company
     *
     * @return \RxConnexionBundle\Entity\CompanyEntity
     */
    public function getCompany()
    {
        return $this->company;
    }

    /**
     * Add accountUserBranch
     *
     * @param \RxConnexionBundle\Entity\AccountUserBranchEntity $accountUserBranch
     *
     * @return BranchEntity
     */
    public function addAccountUserBranch(\RxConnexionBundle\Entity\AccountUserBranchEntity $accountUserBranch)
    {
        $this->accountUserBranches[] = $accountUserBranch;

        return $this;
    }

    /**
     * Remove accountUserBranch
     *
     * @param \RxConnexionBundle\Entity\AccountUserBranchEntity $accountUserBranch
     */
    public function removeAccountUserBranch(\RxConnexionBundle\Entity\AccountUserBranchEntity $accountUserBranch)
    {
        $this->accountUserBranches->removeElement($accountUserBranch);
    }

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