<?php
declare (strict_types=1);

namespace App\Entity\Product;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Access\Access;
use App\Entity\Billing\BillingIntangibleExcludeDate;
use App\Entity\Billing\BillLine;
use App\Entity\Core\Tagg;

//use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * Classe ... qui ...
 */
#[ApiResource(
    operations: [
        new Get(
            security: 'is_granted(\'ROLE_ADMIN\')'
        )
    ]
)]
//#[Auditable]
#[ORM\Entity]
class EquipmentLoan
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(cascade: ['persist'], inversedBy: 'equipmentLoans')]
    #[ORM\JoinColumn(nullable: false)]
    private Access $borrower;

    #[ORM\ManyToOne(inversedBy: 'equipmentLoan')]
    private Equipment $equipment;

    #[ORM\OneToMany(mappedBy: 'equipmentLoan', targetEntity: BillLine::class, orphanRemoval: true)]
    private Collection $billLines;

    #[ORM\OneToMany(mappedBy: 'equipmentLoan', targetEntity: BillingIntangibleExcludeDate::class, cascade: ['persist'], orphanRemoval: true)]
    private Collection $billingIntangibleExcludeDates;

    #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'equipmentLoans', cascade: ['persist'])]
    #[ORM\JoinTable(name: 'tag_equipmentLoan')]
    #[ORM\JoinColumn(name: 'equipmentLoan_id', referencedColumnName: 'id')]
    #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
    private Collection $tags;

    public function __construct()
    {
        $this->billLines = new ArrayCollection();
        $this->billingIntangibleExcludeDates = new ArrayCollection();
        $this->tags = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getBorrower(): ?Access
    {
        return $this->borrower;
    }

    public function setBorrower(?Access $borrower): self
    {
        $this->borrower = $borrower;
        return $this;
    }

    public function getEquipment(): ?Equipment
    {
        return $this->equipment;
    }

    public function setEquipment(?Equipment $equipment): self
    {
        $this->equipment = $equipment;
        return $this;
    }

    /**
     * @return Collection<int, BillLine>
     */
    public function getBillLines(): Collection
    {
        return $this->billLines;
    }

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

    public function removeBillLine(BillLine $billLine): self
    {
        if ($this->billLines->removeElement($billLine)) {
            // set the owning side to null (unless already changed)
            if ($billLine->getEquipmentLoan() === $this) {
                $billLine->setEquipmentLoan(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, BillingIntangibleExcludeDate>
     */
    public function getBillingIntangibleExcludeDates(): Collection
    {
        return $this->billingIntangibleExcludeDates;
    }

    public function addBillingIntangibleExcludeDate(BillingIntangibleExcludeDate $billingIntangibleExcludeDate): self
    {
        if (!$this->billingIntangibleExcludeDates->contains($billingIntangibleExcludeDate)) {
            $this->billingIntangibleExcludeDates[] = $billingIntangibleExcludeDate;
            $billingIntangibleExcludeDate->setEquipmentLoan($this);
        }
        return $this;
    }

    public function removeBillingIntangibleExcludeDate(BillingIntangibleExcludeDate $billingIntangibleExcludeDate): self
    {
        if ($this->billingIntangibleExcludeDates->removeElement($billingIntangibleExcludeDate)) {
            // set the owning side to null (unless already changed)
            if ($billingIntangibleExcludeDate->getEquipmentLoan() === $this) {
                $billingIntangibleExcludeDate->setEquipmentLoan(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, Tagg>
     */
    public function getTags(): Collection
    {
        return $this->tags;
    }

    public function addTag(Tagg $tag): self
    {
        if (!$this->tags->contains($tag)) {
            $this->tags[] = $tag;
        }
        return $this;
    }

    public function removeTag(Tagg $tag): self
    {
        $this->tags->removeElement($tag);
        return $this;
    }
}
