<?php
declare (strict_types=1);

namespace App\Entity\Billing;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Product\IntangibleDiscountDetail;
//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\') and object.getBillingSetting().getOrganization().getId() == user.getOrganization().getId()'
        )
    ]
)]
//#[Auditable]
#[ORM\Entity]
class FamilyQuotient
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'familyQuotients')]
    #[ORM\JoinColumn(nullable: false)]
    private BillingSetting $billingSetting;

    #[ORM\OneToMany(mappedBy: 'familyQuotient', targetEntity: AccessBilling::class)]
    private Collection $accessBilling;

    #[ORM\OneToMany(mappedBy: 'familyQuotient', targetEntity: IntangibleDiscountDetail::class)]
    private Collection $intangibleDiscountDetails;

    public function __construct()
    {
        $this->accessBilling = new ArrayCollection();
        $this->intangibleDiscountDetails = new ArrayCollection();
    }

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

    public function getBillingSetting(): ?BillingSetting
    {
        return $this->billingSetting;
    }

    public function setBillingSetting(?BillingSetting $billingSetting): self
    {
        $this->billingSetting = $billingSetting;
        return $this;
    }

    /**
     * @return Collection<int, AccessBilling>
     */
    public function getAccessBilling(): Collection
    {
        return $this->accessBilling;
    }

    public function addAccessBilling(AccessBilling $accessBilling): self
    {
        if (!$this->accessBilling->contains($accessBilling)) {
            $this->accessBilling[] = $accessBilling;
            $accessBilling->setFamilyQuotient($this);
        }
        return $this;
    }

    public function removeAccessBilling(AccessBilling $accessBilling): self
    {
        if ($this->accessBilling->removeElement($accessBilling)) {
            // set the owning side to null (unless already changed)
            if ($accessBilling->getFamilyQuotient() === $this) {
                $accessBilling->setFamilyQuotient(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, IntangibleDiscountDetail>
     */
    public function getIntangibleDiscountDetails(): Collection
    {
        return $this->intangibleDiscountDetails;
    }

    public function addIntangibleDiscountDetail(IntangibleDiscountDetail $intangibleDiscountDetail): self
    {
        if (!$this->intangibleDiscountDetails->contains($intangibleDiscountDetail)) {
            $this->intangibleDiscountDetails[] = $intangibleDiscountDetail;
            $intangibleDiscountDetail->setFamilyQuotient($this);
        }
        return $this;
    }

    public function removeIntangibleDiscountDetail(IntangibleDiscountDetail $intangibleDiscountDetail): self
    {
        if ($this->intangibleDiscountDetails->removeElement($intangibleDiscountDetail)) {
            // set the owning side to null (unless already changed)
            if ($intangibleDiscountDetail->getFamilyQuotient() === $this) {
                $intangibleDiscountDetail->setFamilyQuotient(null);
            }
        }
        return $this;
    }
}