<?php
declare (strict_types=1);

namespace App\Entity\Access;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
//use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use App\Entity\Billing\AccessFictionalIntangible;
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 AccessFamily
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\OneToMany(mappedBy: 'accessFamily', targetEntity: Access::class)]
    private Collection $accesses;

    #[ORM\OneToMany(mappedBy: 'accessFamily', targetEntity: AccessFictionalIntangible::class, cascade: ['persist'], orphanRemoval: true)]
    private Collection $accessFictionalIntangibles;

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

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

    /**
     * @return Collection<int, Access>
     */
    public function getAccesses(): Collection
    {
        return $this->accesses;
    }

    public function addAccess(Access $access): self
    {
        if (!$this->accesses->contains($access)) {
            $this->accesses[] = $access;
            $access->setAccessFamily($this);
        }
        return $this;
    }

    public function removeAccess(Access $access): self
    {
        if ($this->accesses->removeElement($access)) {
            // set the owning side to null (unless already changed)
            if ($access->getAccessFamily() === $this) {
                $access->setAccessFamily(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, AccessFictionalIntangible>
     */
    public function getAccessFictionalIntangibles(): Collection
    {
        return $this->accessFictionalIntangibles;
    }

    public function addAccessFictionalIntangible(AccessFictionalIntangible $accessFictionalIntangible): self
    {
        if (!$this->accessFictionalIntangibles->contains($accessFictionalIntangible)) {
            $this->accessFictionalIntangibles[] = $accessFictionalIntangible;
            $accessFictionalIntangible->setAccessFamily($this);
        }
        return $this;
    }

    public function removeAccessFictionalIntangible(AccessFictionalIntangible $accessFictionalIntangible): self
    {
        if ($this->accessFictionalIntangibles->removeElement($accessFictionalIntangible)) {
            // set the owning side to null (unless already changed)
            if ($accessFictionalIntangible->getAccessFamily() === $this) {
                $accessFictionalIntangible->setAccessFamily(null);
            }
        }
        return $this;
    }
}