<?php

declare(strict_types=1);

namespace App\Entity\Product;

use ApiPlatform\Metadata\ApiResource;
use App\Entity\Billing\AccessIntangible;
// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use App\Entity\Education\EducationCurriculum;
use App\Entity\Education\EducationCurriculumPack;
use App\Entity\Organization\Organization;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table Intangible, et supprimer l'attribut discr.
 * @todo : migration table tag_product
 *
 * Service ou produit à facturer (cours)
 */
#[ApiResource(operations: [])]
// #[Auditable]
#[ORM\Entity]
class Intangible extends AbstractProduct
{
    #[ORM\ManyToOne(inversedBy: 'intangibles')]
    protected ?Organization $organization = null;

    /** @var Collection<int, EducationCurriculum> */
    #[ORM\ManyToMany(targetEntity: EducationCurriculum::class, inversedBy: 'intangibles', cascade: ['persist'])]
    protected Collection $educationCurriculums;

    /** @var Collection<int, AccessIntangible> */
    #[ORM\OneToMany(targetEntity: AccessIntangible::class, mappedBy: 'intangible', cascade: ['persist'], orphanRemoval: true)]
    protected Collection $accessIntangibles;

    /** @var Collection<int, EducationCurriculumPack> */
    #[ORM\ManyToMany(targetEntity: EducationCurriculumPack::class, inversedBy: 'intangibles', cascade: [], orphanRemoval: false)]
    protected Collection $educationCurriculumPacks;

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

    public function __construct()
    {
        $this->educationCurriculums = new ArrayCollection();
        $this->accessIntangibles = new ArrayCollection();
        $this->educationCurriculumPacks = new ArrayCollection();
        $this->intangiblePriceAndDiscount = new IntangiblePriceAndDiscount();
        parent::__construct();
    }

    public function getOrganization(): ?Organization
    {
        return $this->organization;
    }

    public function setOrganization(?Organization $organization): self
    {
        $this->organization = $organization;

        return $this;
    }

    /**
     * @return Collection<int, EducationCurriculum>
     */
    public function getEducationCurriculums(): Collection
    {
        return $this->educationCurriculums;
    }

    public function addEducationCurriculum(EducationCurriculum $educationCurriculum): self
    {
        if (!$this->educationCurriculums->contains($educationCurriculum)) {
            $this->educationCurriculums[] = $educationCurriculum;
        }

        return $this;
    }

    public function removeEducationCurriculum(EducationCurriculum $educationCurriculum): self
    {
        $this->educationCurriculums->removeElement($educationCurriculum);

        return $this;
    }

    /**
     * @return Collection<int, AccessIntangible>
     */
    public function getAccessIntangibles(): Collection
    {
        return $this->accessIntangibles;
    }

    public function addAccessIntangible(AccessIntangible $accessIntangible): self
    {
        if (!$this->accessIntangibles->contains($accessIntangible)) {
            $this->accessIntangibles[] = $accessIntangible;
            $accessIntangible->setIntangible($this);
        }

        return $this;
    }

    public function removeAccessIntangible(AccessIntangible $accessIntangible): self
    {
        if ($this->accessIntangibles->removeElement($accessIntangible)) {
            // set the owning side to null (unless already changed)
            if ($accessIntangible->getIntangible() === $this) {
                $accessIntangible->setIntangible(null);
            }
        }

        return $this;
    }

    public function getEducationCurriculumPacks(): Collection
    {
        return $this->educationCurriculumPacks;
    }

    public function addEducationCurriculumPack(EducationCurriculumPack $educationCurriculumPack): self
    {
        if (!$this->educationCurriculumPacks->contains($educationCurriculumPack)) {
            $this->educationCurriculumPacks[] = $educationCurriculumPack;
            $educationCurriculumPack->addIntangible($this);
        }

        return $this;
    }

    public function removeEducationCurriculumPack(EducationCurriculumPack $educationCurriculumPack): self
    {
        if ($this->educationCurriculumPacks->removeElement($educationCurriculumPack)) {
            $educationCurriculumPack->removeIntangible($this);
        }

        return $this;
    }

    public function getIntangiblePriceAndDiscount(): ?IntangiblePriceAndDiscount
    {
        return $this->intangiblePriceAndDiscount;
    }

    public function setIntangiblePriceAndDiscount(?IntangiblePriceAndDiscount $intangiblePriceAndDiscount): self
    {
        $this->intangiblePriceAndDiscount = $intangiblePriceAndDiscount;

        return $this;
    }
}
