<?php

namespace AppBundle\Entity\Bank;

use AppBundle\Entity\AccessAndFunction\Access;
use Doctrine\ORM\Mapping as ORM;
use Dunglas\ApiBundle\Annotation\Iri;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Entity\Organization\Organization;
use AppBundle\Entity\Person\Person;
use AppBundle\Entity\Traits\TimestampableEntity;
use AppBundle\Entity\Traits\CreatorUpdaterEntity;

/**
 * Coordonnées bancaires des Person et Organization
 *
 * @Iri("http://schema.org/BankAccount")
 */
#[ORM\Entity(repositoryClass: 'AppBundle\Entity\Bank\Repository\BankAccountRepository')]
class BankAccount
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['bankaccount', 'access_details_person', 'organization_details', 'sepa_debit_mandate_person', 'build_bills_access'])]
    private $id;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Length(max: 255, maxMessage: 'invalid-max-length')]
    #[Groups(['bankaccount', 'access_details_person', 'organization_details_bankaccount', 'build_bills_access'])]
    private $bankName;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 11, nullable: true)]
    #[Assert\Bic(message: 'This is not a valid Business Identifier Code (BIC).')]
    #[Groups(['bankaccount', 'access_details_person', 'organization_details_bankaccount', 'sepa_debit_mandate_person', 'build_bills_access'])]
    private $bic;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    #[Groups(['bankaccount'])]
    private $bicInvalid;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 34, nullable: true)]
    #[Assert\Iban(message: 'This is not a valid International Bank Account Number (IBAN).')]
    #[Groups(['bankaccount', 'access_details_person', 'organization_details_bankaccount', 'sepa_debit_mandate_person', 'build_bills_access'])]
    private $iban;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    #[Groups(['bankaccount'])]
    private $ibanInvalid;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['bankaccount', 'access_details_person', 'sepa_debit_mandate_person', 'build_bills_access'])]
    private $holderIdDifferent = false;
    /**
     * 0 => jamais facturé, 1 => facturé 1 fois, 2 => facturé plusieurs fois
     * @var int
     */
    #[ORM\Column(type: 'integer', nullable: true, options: ['default' => 0])]
    #[Groups(['bankaccount', 'access_details_person', 'sepa_debit_mandate_person', 'build_bills_access'])]
    private $countInvoiced = 0;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['bankaccount', 'access_details_person', 'sepa_debit_mandate_person', 'build_bills_access'])]
    private $holder;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['bankaccount', 'access_details_person', 'sepa_debit_mandate_person', 'build_bills_access'])]
    private $principal = false;
    /**
     * @var string
     */
    #[ORM\Column(type: 'text', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Length(max: 255, maxMessage: 'invalid-max-length')]
    #[Groups(['bankaccount', 'access_details_person', 'build_bills_access'])]
    private $debitAddress;
    /**
     * @var Organization
     */
    #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Organization\Organization', mappedBy: 'bankAccount', cascade: ['persist'])]
    private $organization;
    /**
     * @var Person
     */
    #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Person\Person', mappedBy: 'bankAccount', cascade: ['persist'])]
    private $person;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 35, unique: true, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['bankaccount', 'access_details_person', 'sepa_debit_mandate_person', 'build_bills_access'])]
    #[Assert\Length(max: 35, maxMessage: 'invalid-max-length')]
    private $rum;
    /**
     * @var
     *
     * @Iri("https://schema.org/birthDate")
     */
    #[ORM\Column(type: 'date', nullable: true)]
    #[Assert\Date(message: 'invalid-date')]
    #[Groups(['bankaccount', 'access_details_person', 'build_bills_access'])]
    private $signatureDateSamplingMandate;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->organization = new \Doctrine\Common\Collections\ArrayCollection();
        $this->person = new \Doctrine\Common\Collections\ArrayCollection();
    }
    /**
     * Sets id.
     *
     * @param int $id
     *
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }
    /**
     * Gets id.
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Get organization
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOrganization()
    {
        return $this->organization;
    }
    /**
     * Get person
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getPerson()
    {
        return $this->person;
    }
    /**
     * Sets bankName.
     *
     * @param string $bankName
     *
     * @return $this
     */
    public function setBankName($bankName)
    {
        $this->bankName = $bankName;

        return $this;
    }
    /**
     * Gets bankName.
     *
     * @return string
     */
    public function getBankName()
    {
        return $this->bankName;
    }
    /**
     * Sets bic.
     *
     * @param string $bic
     *
     * @return $this
     */
    public function setBic($bic)
    {
        $this->bic = $bic;

        if(!is_null($bic) && !is_null($this->getBicInvalid()))
            $this->setBicInvalid(NULL);

        return $this;
    }
    /**
     * Gets bic.
     *
     * @return string
     */
    public function getBic()
    {
        return $this->bic;
    }
    /**
     * Sets bic Invalid.
     *
     * @param string $bicInvalid
     *
     * @return $this
     */
    public function setBicInvalid($bicInvalid)
    {
        $this->bicInvalid = is_null($this->bic) ? $bicInvalid : NULL;
        return $this;
    }
    /**
     * Gets bic Invalid.
     *
     * @return string
     */
    public function getBicInvalid()
    {
        return $this->bicInvalid;
    }
    /**
     * Sets iban.
     *
     * @param string $iban
     *
     * @return $this
     */
    public function setIban($iban)
    {
        $this->iban = $iban;

        if(!is_null($iban) && !is_null($this->getIbanInvalid()))
            $this->setIbanInvalid(NULL);

        return $this;
    }
    /**
     * Gets iban.
     *
     * @return string
     */
    public function getIban()
    {
        return $this->iban;
    }
    /**
     * Sets ibanInvalid.
     *
     * @param string $ibanInvalid
     *
     * @return $this
     */
    public function setIbanInvalid($ibanInvalid)
    {
        $this->ibanInvalid = is_null($this->iban) ? $ibanInvalid : NULL;

        return $this;
    }
    /**
     * Gets ibanInvalid.
     *
     * @return string
     */
    public function getIbanInvalid()
    {
        return $this->ibanInvalid;
    }
    /**
     * Sets holder.
     *
     * @param string $holder
     *
     * @return $this
     */
    public function setHolder($holder)
    {
        $this->holder = $holder;

        return $this;
    }
    /**
     * Gets holder.
     *
     * @return string
     */
    public function getHolder()
    {
        return $this->holder;
    }
    /**
     * Sets principal.
     *
     * @param bool $principal
     *
     * @return $this
     */
    public function setPrincipal($principal)
    {
        $this->principal = $principal;

        return $this;
    }
    /**
     * Gets principal.
     *
     * @return bool
     */
    public function getPrincipal()
    {
        return $this->principal;
    }
    /**
     * Sets debitAddress.
     *
     * @param string $debitAddress
     *
     * @return $this
     */
    public function setDebitAddress($debitAddress)
    {
        $this->debitAddress = $debitAddress;

        return $this;
    }
    /**
     * Gets debitAddress.
     *
     * @return string
     */
    public function getDebitAddress()
    {
        return $this->debitAddress;
    }
    /**
     * Add organization
     *
     * @param \AppBundle\Entity\Organization\Organization $organization
     *
     * @return BankAccount
     */
    public function addOrganization(\AppBundle\Entity\Organization\Organization $organization)
    {
        $this->organization[] = $organization;

        return $this;
    }
    /**
     * Remove organization
     *
     * @param \AppBundle\Entity\Organization\Organization $organization
     */
    public function removeOrganization(\AppBundle\Entity\Organization\Organization $organization)
    {
        $this->organization->removeElement($organization);
    }
    /**
     * Add person
     *
     * @param \AppBundle\Entity\Person\Person $person
     *
     * @return BankAccount
     */
    public function addPerson(\AppBundle\Entity\Person\Person $person)
    {
        $this->person[] = $person;

        return $this;
    }
    /**
     * Remove person
     *
     * @param \AppBundle\Entity\Person\Person $person
     */
    public function removePerson(\AppBundle\Entity\Person\Person $person)
    {
        $this->person->removeElement($person);
    }
    /**
     * Get rum
     *
     * @return string
     */
    public function getRum()
    {
        return $this->rum;
    }
    /**
     * Set rum
     *
     * @param string $rum
     *
     * @return BankAccount
     */
    public function setRum($rum)
    {
        $this->rum = $rum;

        return $this;
    }
    /**
     * Set signatureDateSamplingMandate
     *
     * @param \DateTime $signatureDateSamplingMandate
     *
     * @return BankAccount
     */
    public function setSignatureDateSamplingMandate($signatureDateSamplingMandate)
    {
        $this->signatureDateSamplingMandate = $signatureDateSamplingMandate;

        return $this;
    }
    /**
     * Get signatureDateSamplingMandate
     *
     * @return \DateTime
     */
    public function getSignatureDateSamplingMandate()
    {
        return $this->signatureDateSamplingMandate ? $this->signatureDateSamplingMandate->format('Y-m-d') : $this->signatureDateSamplingMandate;
    }
    /**
     * Set holderIdDifferent
     *
     * @param boolean $holderIdDifferent
     *
     * @return BankAccount
     */
    public function setHolderIdDifferent($holderIdDifferent)
    {
        $this->holderIdDifferent = $holderIdDifferent;

        return $this;
    }
    /**
     * Get holderIdDifferent
     *
     * @return boolean
     */
    public function getHolderIdDifferent()
    {
        return $this->holderIdDifferent;
    }
    /**
     * Set countInvoiced
     *
     * @param integer $countInvoiced
     *
     * @return BankAccount
     */
    public function setCountInvoiced($countInvoiced)
    {
        $this->countInvoiced = $countInvoiced;

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