<?php

declare(strict_types=1);

namespace App\Entity\Product;

// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Billing\FamilyQuotientModel;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * Prix et application d'éventuelles réductions sur un Intangible.
 */
// #[Auditable]
#[ApiResource(operations: [])]
#[ORM\Entity]
class IntangiblePriceAndDiscount
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    #[Groups('access_people_ref')]
    private ?int $id = null;

    /** @var Collection<int, IntangibleDiscountDetail> */
    #[ORM\OneToMany(
        targetEntity: IntangibleDiscountDetail::class,
        mappedBy: 'intangiblePriceAndDiscount',
        cascade: ['persist'],
        orphanRemoval: true
    )]
    private Collection $intangibleDiscountDetails;

    #[ORM\OneToOne(targetEntity: Intangible::class, mappedBy: 'intangiblePriceAndDiscount', cascade: [])]
    protected ?Intangible $intangible;

    #[ORM\ManyToOne(targetEntity: FamilyQuotientModel::class, cascade: [], inversedBy: 'intangiblePriceAndDiscounts')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    protected ?FamilyQuotientModel $familyQuotientModel;

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

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

    /**
     * @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->setIntangiblePriceAndDiscount($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->getIntangiblePriceAndDiscount() === $this) {
                $intangibleDiscountDetail->setIntangiblePriceAndDiscount(null);
            }
        }

        return $this;
    }

    public function getIntangible(): ?Intangible
    {
        return $this->intangible;
    }

    public function setIntangible(?Intangible $intangible): self
    {
        $this->intangible = $intangible;

        return $this;
    }

    public function getFamilyQuotientModel(): ?FamilyQuotientModel
    {
        return $this->familyQuotientModel;
    }

    public function setFamilyQuotientModel(?FamilyQuotientModel $familyQuotientModel): self
    {
        $this->familyQuotientModel = $familyQuotientModel;

        return $this;
    }
}
