<?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\FinancingCompanyRepository")
 * @ORM\Table(name="financing_company", indexes={@ORM\Index(name="IDX_SEARCH_000", columns={"description"})})
 */

class FinancingCompanyEntity extends BaseEntity
{

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @ORM\Column(name="is_active", type="boolean")
     * @Groups("forAudit")
     */
    protected $isActive;

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="CityEntity", inversedBy="financingCompanies")
     * @ORM\JoinColumn(name="city_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $city;

    /**
     * @ORM\ManyToOne(targetEntity="PostalCodeEntity", inversedBy="financingCompanies")
     * @ORM\JoinColumn(name="postal_code_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $postalCode;

    /**
     * @ORM\OneToMany(targetEntity="PatientPaymentEntity", mappedBy="financingCompany")
     */
    protected $patientPayments;

    public function __construct()
    {
    }

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

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

    /**
     * Concatenate address
     */
    public function updateAddress() {
        $this->address = $this->street . ' ' . ($this->city ? $this->city->getDescription() . ', ' . ($this->city->getProvince() != null ? $this->city->getProvince()->getDescription() : '') . ' ' . ($this->city->getProvince() != null ? $this->city->getProvince()->getCountry()->getDescription() : '')  . ' ' : '') . ($this->getPostalCode() ? $this->getPostalCode()->getDescription() : '');
    }

    /**
     * Remove the photo from the disk
     *
     * @ORM\PreRemove
     */
    public function removePhoto() {

        $file = $this->getUploadRootDir() . '/' . $this->parsedPhotoDesc;
        if(!empty($this->parsedPhotoDesc) && file_exists($file)) unlink($file);
    }


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

    /**
     * Get uploadDir
     *
     * @return string
     */
    public function getUploadDir() {

        return 'uploads/financing_company/photo';
    }

    /**
     * Get uploadRootDir
     *
     * @return string
     */
    public function getUploadRootDir() {

        return __DIR__ . '/../../../web/' . $this->getUploadDir();
    }

    /**
     * get photoWebPath
     *
     * @return string
     */
    public function getPhotoWebPath() {

        $parsedDesc = $this->parsedPhotoDesc;
        $file = $this->getUploadRootDir() . '/' . $parsedDesc;

        if(!empty($parsedDesc) && file_exists($file)) {
            return '/' . $this->getUploadDir() . '/' . $parsedDesc;
        } else {
            return '';
        }
    }

    /**
     * Get concatenatedMobileNo
     *
     * return string
     */
    public function getConcatenatedMobileNo() {

        $mobileNos = '';
        if(!empty($this->mobileNo)) $mobileNos .= (!empty($mobileNos) ? ', ' : '') . $this->mobileNo;
        if(!empty($this->mobileNoTwo)) $mobileNos .= (!empty($mobileNos) ? ', ' : '') . $this->mobileNoTwo;

        return $mobileNos;
    }

    /**
     * Get concatenatedPhoneNo
     *
     * return string
     */
    public function getConcatenatedPhoneNo() {

        $phoneNos = '';
        if(!empty($this->phoneNo)) $phoneNos .= (!empty($phoneNos) ? ', ' : '') . $this->phoneNo;
        if(!empty($this->phoneNoTwo)) $phoneNos .= (!empty($phoneNos) ? ', ' : '') . $this->phoneNoTwo;

        return $phoneNos;
    }

    /**
     * Get concatenatedEmail
     *
     * return string
     */
    public function getConcatenatedEmail() {

        $emails = '';
        if(!empty($this->email)) $emails .= (!empty($emails) ? ', ' : '') . $this->email;
        if(!empty($this->emailTwo)) $emails .= (!empty($emails) ? ', ' : '') . $this->emailTwo;

        return $emails;
    }
    /*--------------------------------------------------------------------------------------------------------*/
    /*					Setters and Getters																	  */
    /*--------------------------------------------------------------------------------------------------------*/


    /**
     * Set isDeleted
     *
     * @param boolean $isDeleted
     *
     * @return FinancingCompanyEntity
     */
    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 FinancingCompanyEntity
     */
    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 FinancingCompanyEntity
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

    /**
     * Set mobileNo
     *
     * @param string $mobileNo
     *
     * @return FinancingCompanyEntity
     */
    public function setMobileNo($mobileNo)
    {
        $this->mobileNo = $mobileNo;

        return $this;
    }

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

    /**
     * Set mobileNoTwo
     *
     * @param string $mobileNoTwo
     *
     * @return FinancingCompanyEntity
     */
    public function setMobileNoTwo($mobileNoTwo)
    {
        $this->mobileNoTwo = $mobileNoTwo;

        return $this;
    }

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

    /**
     * Set phoneNo
     *
     * @param string $phoneNo
     *
     * @return FinancingCompanyEntity
     */
    public function setPhoneNo($phoneNo)
    {
        $this->phoneNo = $phoneNo;

        return $this;
    }

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

    /**
     * Set phoneNoTwo
     *
     * @param string $phoneNoTwo
     *
     * @return FinancingCompanyEntity
     */
    public function setPhoneNoTwo($phoneNoTwo)
    {
        $this->phoneNoTwo = $phoneNoTwo;

        return $this;
    }

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

    /**
     * Set faxNo
     *
     * @param string $faxNo
     *
     * @return FinancingCompanyEntity
     */
    public function setFaxNo($faxNo)
    {
        $this->faxNo = $faxNo;

        return $this;
    }

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

    /**
     * Set faxNoTwo
     *
     * @param string $faxNoTwo
     *
     * @return FinancingCompanyEntity
     */
    public function setFaxNoTwo($faxNoTwo)
    {
        $this->faxNoTwo = $faxNoTwo;

        return $this;
    }

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

    /**
     * Set email
     *
     * @param string $email
     *
     * @return FinancingCompanyEntity
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

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

    /**
     * Set emailTwo
     *
     * @param string $emailTwo
     *
     * @return FinancingCompanyEntity
     */
    public function setEmailTwo($emailTwo)
    {
        $this->emailTwo = $emailTwo;

        return $this;
    }

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

    /**
     * Set street
     *
     * @param string $street
     *
     * @return FinancingCompanyEntity
     */
    public function setStreet($street)
    {
        $this->street = $street;

        return $this;
    }

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

    /**
     * Set address
     *
     * @param string $address
     *
     * @return FinancingCompanyEntity
     */
    public function setAddress($address)
    {
        $this->address = $address;

        return $this;
    }

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

    /**
     * Set city
     *
     * @param \RxConnexionBundle\Entity\CityEntity $city
     *
     * @return FinancingCompanyEntity
     */
    public function setCity(\RxConnexionBundle\Entity\CityEntity $city = null)
    {
        $this->city = $city;

        return $this;
    }

    /**
     * Get city
     *
     * @return \RxConnexionBundle\Entity\CityEntity
     */
    public function getCity()
    {
        return $this->city;
    }

    /**
     * Set postalCode
     *
     * @param \RxConnexionBundle\Entity\PostalCodeEntity $postalCode
     *
     * @return FinancingCompanyEntity
     */
    public function setPostalCode(\RxConnexionBundle\Entity\PostalCodeEntity $postalCode = null)
    {
        $this->postalCode = $postalCode;

        return $this;
    }

    /**
     * Get postalCode
     *
     * @return \RxConnexionBundle\Entity\PostalCodeEntity
     */
    public function getPostalCode()
    {
        return $this->postalCode;
    }

    /**
     * Add patientPayment
     *
     * @param \RxConnexionBundle\Entity\PatientPaymentEntity $patientPayment
     *
     * @return FinancingCompanyEntity
     */
    public function addPatientPayment(\RxConnexionBundle\Entity\PatientPaymentEntity $patientPayment)
    {
        $this->patientPayments[] = $patientPayment;

        return $this;
    }

    /**
     * Remove patientPayment
     *
     * @param \RxConnexionBundle\Entity\PatientPaymentEntity $patientPayment
     */
    public function removePatientPayment(\RxConnexionBundle\Entity\PatientPaymentEntity $patientPayment)
    {
        $this->patientPayments->removeElement($patientPayment);
    }

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

    /**
     * Set isActive
     *
     * @param boolean $isActive
     *
     * @return FinancingCompanyEntity
     */
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;

        return $this;
    }

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

    /**
     * Set photoDesc
     *
     * @param string $photoDesc
     *
     * @return FinancingCompanyEntity
     */
    public function setPhotoDesc($photoDesc)
    {
        $this->photoDesc = $photoDesc;

        return $this;
    }

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

    /**
     * Set parsedPhotoDesc
     *
     * @param string $parsedPhotoDesc
     *
     * @return FinancingCompanyEntity
     */
    public function setParsedPhotoDesc($parsedPhotoDesc)
    {
        $this->parsedPhotoDesc = $parsedPhotoDesc;

        return $this;
    }

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

    /**
     * Set lastOrNumber
     *
     * @param integer $lastOrNumber
     *
     * @return FinancingCompanyEntity
     */
    public function setLastOrNumber($lastOrNumber)
    {
        $this->lastOrNumber = $lastOrNumber;

        return $this;
    }

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