<?php

namespace App\Entity\Billing;

use AppBundle\Entity\AccessAndFunction\Access;
use AppBundle\Entity\Core\Tagg;
use AppBundle\Enum\Billing\PaymentChoiceEnum;
use Doctrine\Common\Collections\ArrayCollection;
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\Traits\TimestampableEntity;
use AppBundle\Entity\Traits\CreatorUpdaterEntity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;


/**
 * Données de paiement d'une facture BillAccounting
 * NB: il peut y avoir plusieurs lignes pour une facture en cas de paiement en plusieurs fois
 *
 * @Iri("http://schema.org/BillPayment")
 */
#[ORM\Entity]
class BillPayment
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['billpayment', 'billpayment_list', 'build_bills', 'billpayment_list', 'account_balance_reimbursements_accessbilling'])]
    private $id;
    /**
     * @var BillAccounting
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Billing\BillAccounting', inversedBy: 'billPayments', cascade: ['persist'])]
    #[ORM\JoinColumn(nullable: true)]
    #[Groups(['billpayment', 'billpayment_list'])]
    private $bill;
    /**
     * @var AccessBilling
     */
    #[ORM\ManyToOne(targetEntity: 'AccessBilling', inversedBy: 'billDetachedPayments', cascade: ['persist'])]
    #[ORM\JoinColumn(nullable: true)]
    #[Groups(['billpayment'])]
    private $accessBilling;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'date', nullable: true)]
    #[Assert\Date]
    #[Groups(['billpayment', 'billpayment_list', 'build_bills_billpayments'])]
    private $receiptDate;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'date', nullable: true)]
    #[Assert\Date]
    #[Groups(['billpayment', 'billpayment_list', 'build_bills_billpayments', 'billpayment_list', 'account_balance_reimbursements_accessbilling'])]
    private $effectiveReceiptDate;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Choice(callback: ['\AppBundle\Enum\Billing\PaymentChoiceEnum', 'toArray'])]
    #[Groups(['billpayment', 'billpayment_list', 'build_bills_billpayments', 'billpayment_list', 'account_balance_reimbursements_accessbilling'])]
    private $paymentChoice;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Choice(callback: ['\AppBundle\Enum\Billing\BankEnum', 'toArray'])]
    #[Groups(['billpayment', 'billpayment_list', 'account_balance_reimbursements_accessbilling'])]
    private $bank;
    /**
     * @var string
     *
     *
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['billpayment', 'billpayment_list', 'account_balance_reimbursements_accessbilling'])]
    private $agency;
    /**
     * @var string
     *
     *
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['billpayment', 'billpayment_list', 'account_balance_reimbursements_accessbilling'])]
    private $checkNumber;
    /**
     * @var string
     *
     *
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['billpayment', 'billpayment_list', 'account_balance_reimbursements_accessbilling'])]
    private $reference;
    /**
     * @var float
     */
    #[ORM\Column(type: 'float', nullable: true)]
    #[Assert\Type(type: 'float')]
    #[Groups(['billpayment', 'billpayment_list', 'account_balance_reimbursements_accessbilling', 'billpayment_list', 'build_bills_billpayments'])]
    private $amount;
    /**
     * @var BillDebitBalance
     */
    #[ORM\OneToMany(targetEntity: 'BillDebitBalance', mappedBy: 'billPayment', cascade: ['persist'], orphanRemoval: true)]
    #[ORM\JoinColumn(nullable: true)]
    #[Groups(['billpayment_billdebitbalance'])]
    private $billDebitBalances;
    /**
     * @var AccessBilling
     */
    #[ORM\ManyToOne(targetEntity: 'AccessBilling', inversedBy: 'accountBalanceReimbursements', cascade: ['persist'])]
    #[ORM\JoinColumn(nullable: true)]
    #[Groups(['billpayment', 'billpayment_list'])]
    private $accessBillingAccountBalanceReimbursement;
    /**
     * @var boolean
     */
    #[Groups(['billpayment', 'billpayment_list'])]
    private $isAcquired;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', options: ['default' => 'PAYMENT'])]
    #[Assert\Type(type: 'string')]
    #[Assert\NotNull]
    #[Assert\Choice(callback: ['\AppBundle\Enum\Billing\PaymentTypeEnum', 'toArray'])]
    #[Groups(['billpayment', 'billpayment_list', 'account_balance_reimbursements_accessbilling', 'build_bills_billpayments'])]
    private $type= 'PAYMENT';
    /**
     * @var ArrayCollection<Tagg>
     */
    #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Core\Tagg', cascade: ['persist'], inversedBy: 'payments')]
    #[Assert\Valid]
    #[ORM\JoinTable(name: 'tag_billPayment', joinColumns: [], inverseJoinColumns: [])]
    #[ORM\JoinColumn(name: 'billPayment_id', referencedColumnName: 'id')]
    #[ORM\JoinColumn(name: 'tag_id', referencedColumnName: 'id')]
    #[Groups(['billpayment_tags', 'manage_tags', 'billpayment_list'])]
    private $tags;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->billDebitBalances = new ArrayCollection();
        $this->tags = new 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;
    }
    /**
     * Set receiptDate
     *
     * @param \DateTime $receiptDate
     *
     * @return BillPayment
     */
    public function setReceiptDate($receiptDate)
    {
        $this->receiptDate = $receiptDate;

        return $this;
    }
    /**
     * Get receiptDate
     *
     * @return \DateTime
     */
    public function getReceiptDate()
    {
        return $this->receiptDate ? $this->receiptDate->format('Y-m-d') : $this->receiptDate;
    }
    /**
     * Set effectiveReceiptDate
     *
     * @param \DateTime $effectiveReceiptDate
     *
     * @return BillPayment
     */
    public function setEffectiveReceiptDate($effectiveReceiptDate)
    {
        $this->effectiveReceiptDate = $effectiveReceiptDate;

        return $this;
    }
    /**
     * Get effectiveReceiptDate
     *
     * @return \DateTime
     */
    public function getEffectiveReceiptDate()
    {
        return $this->effectiveReceiptDate ? $this->effectiveReceiptDate->format('Y-m-d') : $this->effectiveReceiptDate;
    }
    /**
     * Set paymentChoice
     *
     * @param string $paymentChoice
     *
     * @return BillPayment
     */
    public function setPaymentChoice($paymentChoice)
    {
        $this->paymentChoice = $paymentChoice;

        return $this;
    }
    /**
     * Get paymentChoice
     *
     * @return string
     */
    public function getPaymentChoice()
    {
        return $this->paymentChoice;
    }
    /**
     * Set bank
     *
     * @param string $bank
     *
     * @return BillPayment
     */
    public function setBank($bank)
    {
        $this->bank = $bank;

        return $this;
    }
    /**
     * Get bank
     *
     * @return string
     */
    public function getBank()
    {
        return $this->bank;
    }
    /**
     * Set agency
     *
     * @param string $agency
     *
     * @return BillPayment
     */
    public function setAgency($agency)
    {
        $this->agency = $agency;

        return $this;
    }
    /**
     * Get agency
     *
     * @return string
     */
    public function getAgency()
    {
        return $this->agency;
    }
    /**
     * Set checkNumber
     *
     * @param string $checkNumber
     *
     * @return BillPayment
     */
    public function setCheckNumber($checkNumber)
    {
        $this->checkNumber = $checkNumber;

        return $this;
    }
    /**
     * Get checkNumber
     *
     * @return string
     */
    public function getCheckNumber()
    {
        return $this->checkNumber;
    }
    /**
     * Set reference
     *
     * @param string $reference
     *
     * @return BillPayment
     */
    public function setReference($reference)
    {
        $this->reference = $reference;

        return $this;
    }
    /**
     * Get reference
     *
     * @return string
     */
    public function getReference()
    {
        return $this->reference;
    }
    /**
     * Set amount
     *
     * @param float $amount
     *
     * @return BillPayment
     */
    public function setAmount($amount)
    {
        $this->amount = floatval($amount);

        return $this;
    }
    /**
     * Get amount
     *
     * @return float
     */
    public function getAmount()
    {
        return $this->amount;
    }
    /**
     * Set bill
     *
     * @param \AppBundle\Entity\Billing\BillAccounting $bill
     *
     * @return BillPayment
     */
    public function setBill($bill = null)
    {
        $this->bill = $bill;

        return $this;
    }
    /**
     * Get bill
     *
     * @return \AppBundle\Entity\Billing\BillAccounting
     */
    public function getBill()
    {
        return $this->bill;
    }
    /**
     * Gets isAcquired.
     *
     * @return boolean
     */
    public function getIsAcquired()
    {
        $isAcquired = false;
        if($this->getAmount() && !is_null($this->getEffectiveReceiptDate())){
            $isAcquired = true;
        }
        return $isAcquired;
    }
    /**
     * Set accessBilling
     *
     * @param \AppBundle\Entity\Billing\AccessBilling $accessBilling
     *
     * @return BillPayment
     */
    public function setAccessBilling(\AppBundle\Entity\Billing\AccessBilling $accessBilling = null)
    {
        $this->accessBilling = $accessBilling;

        return $this;
    }
    /**
     * Get accessBilling
     *
     * @return \AppBundle\Entity\Billing\AccessBilling
     */
    public function getAccessBilling()
    {
        return $this->accessBilling;
    }
    /**
     * Add billDebitBalance
     *
     * @param \AppBundle\Entity\Billing\BillDebitBalance $billDebitBalance
     *
     * @return BillPayment
     */
    public function addBillDebitBalance(\AppBundle\Entity\Billing\BillDebitBalance $billDebitBalance)
    {
        $billDebitBalance->setBillPayment($this);
        $this->billDebitBalances[] = $billDebitBalance;

        return $this;
    }
    /**
     * Remove billDebitBalance
     *
     * @param \AppBundle\Entity\Billing\BillDebitBalance $billDebitBalance
     */
    public function removeBillDebitBalance(\AppBundle\Entity\Billing\BillDebitBalance $billDebitBalance)
    {
        $this->billDebitBalances->removeElement($billDebitBalance);
    }
    /**
     * Get billDebitBalances
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getBillDebitBalances()
    {
        return $this->billDebitBalances;
    }
    /**
     * Set type
     *
     * @param string $type
     *
     * @return BillPayment
     */
    public function setType($type)
    {
        $this->type = $type;

        return $this;
    }
    /**
     * Get type
     *
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }
    /**
     * Add tag
     *
     * @param \AppBundle\Entity\Core\Tagg $tag
     *
     * @return BillPayment
     */
    public function addTag(\AppBundle\Entity\Core\Tagg $tag)
    {
        $this->tags[] = $tag;

        return $this;
    }
    /**
     * Remove tag
     *
     * @param \AppBundle\Entity\Core\Tagg $tag
     */
    public function removeTag(\AppBundle\Entity\Core\Tagg $tag)
    {
        $this->tags->removeElement($tag);
    }
    /**
     * Get tags
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getTags()
    {
        return $this->tags;
    }
    /**
     * Set accessBillingAccountBalanceReimbursement
     *
     * @param \AppBundle\Entity\Billing\AccessBilling $accessBillingAccountBalanceReimbursement
     *
     * @return BillPayment
     */
    public function setAccessBillingAccountBalanceReimbursement(\AppBundle\Entity\Billing\AccessBilling $accessBillingAccountBalanceReimbursement = null)
    {
        $this->accessBillingAccountBalanceReimbursement = $accessBillingAccountBalanceReimbursement;

        return $this;
    }
    /**
     * Get accessBillingAccountBalanceReimbursement
     *
     * @return \AppBundle\Entity\Billing\AccessBilling
     */
    public function getAccessBillingAccountBalanceReimbursement()
    {
        return $this->accessBillingAccountBalanceReimbursement;
    }
}
