<?php

declare(strict_types=1);

namespace App\Entity\Billing;

use ApiPlatform\Metadata\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * Facture.
 */
#[ApiResource(operations: [])]
// #[Auditable]
#[ORM\Entity]
class Bill extends AbstractBillAccounting
{
    /** @var Collection<int, BillLine> */
    #[ORM\OneToMany(targetEntity: BillLine::class, mappedBy: 'bill', cascade: ['persist', 'remove'])]
    protected Collection $billLines;

    /** @var Collection<int, BillCredit> */
    #[ORM\OneToMany(targetEntity: BillCredit::class, mappedBy: 'bill', cascade: ['persist', 'remove'])]
    protected Collection $billCredits;

    /** @var Collection<int, BillPayment> */
    #[ORM\OneToMany(targetEntity: BillPayment::class, mappedBy: 'bill', cascade: ['persist', 'remove'])]
    protected Collection $billPayments;

    /** @var Collection<int, PayfipPaymentReturn> */
    #[ORM\OneToMany(targetEntity: PayfipPaymentReturn::class, mappedBy: 'bill', cascade: ['persist', 'remove'])]
    protected Collection $payfipPaymentReturns;

    public function __construct()
    {
        $this->billLines = new ArrayCollection();
        $this->billCredits = new ArrayCollection();
        $this->billPayments = new ArrayCollection();
        $this->payfipPaymentReturns = new ArrayCollection();
        parent::__construct();
    }

    public function getBillLines(): Collection
    {
        return $this->billLines;
    }

    public function addBillLine(BillLine $billLine): self
    {
        if (!$this->billLines->contains($billLine)) {
            $this->billLines[] = $billLine;
            $billLine->setBill($this);
        }

        return $this;
    }

    public function removeBillLine(BillLine $billLine): self
    {
        $this->billLines->removeElement($billLine);

        return $this;
    }

    public function getBillCredits(): Collection
    {
        return $this->billCredits;
    }

    public function addBillCredit(BillCredit $billCredit): self
    {
        if (!$this->billCredits->contains($billCredit)) {
            $this->billCredits[] = $billCredit;
            $billCredit->setBill($this);
        }

        return $this;
    }

    public function removeBillCredit(BillCredit $billCredit): self
    {
        if ($this->billCredits->removeElement($billCredit)) {
            // set the owning side to null (unless already changed)
            if ($billCredit->getBill() === $this) {
                $billCredit->setBill(null);
            }
        }

        return $this;
    }

    public function getBillPayments(): Collection
    {
        return $this->billPayments;
    }

    public function addBillPayment(BillPayment $billPayment): self
    {
        if (!$this->billPayments->contains($billPayment)) {
            $this->billPayments[] = $billPayment;
            $billPayment->setBill($this);
        }

        return $this;
    }

    public function removeBillPayment(BillPayment $billPayment): self
    {
        if ($this->billPayments->removeElement($billPayment)) {
            // set the owning side to null (unless already changed)
            if ($billPayment->getBill() === $this) {
                $billPayment->setBill(null);
            }
        }

        return $this;
    }

    public function getPayfipPaymentReturns(): Collection
    {
        return $this->payfipPaymentReturns;
    }

    public function addPayfipPaymentReturn(PayfipPaymentReturn $payfipPaymentReturn): self
    {
        if (!$this->payfipPaymentReturns->contains($payfipPaymentReturn)) {
            $this->payfipPaymentReturns[] = $payfipPaymentReturn;
            $payfipPaymentReturn->setBill($this);
        }

        return $this;
    }

    public function removePayfipPaymentReturn(PayfipPaymentReturn $payfipPaymentReturn): self
    {
        if ($this->payfipPaymentReturns->removeElement($payfipPaymentReturn)) {
            // set the owning side to null (unless already changed)
            if ($payfipPaymentReturn->getBill() === $this) {
                $payfipPaymentReturn->setBill(null);
            }
        }

        return $this;
    }
}
