<?php

declare(strict_types=1);

namespace App\Entity\AccessWish;

use ApiPlatform\Metadata\ApiResource;
use App\Entity\Core\File;
use App\Entity\Person\Person;
// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * TODO: documenter.
 */
// #[Auditable]
#[ApiResource(operations: [])]
#[ORM\Entity]
class DocumentWish
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'documentWishes')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private ?AccessWish $accessWish = null;

    #[ORM\ManyToOne(inversedBy: 'documentWishes')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private ?Person $personOwner = null;

    /** @var Collection<int, File> */
    #[ORM\OneToMany(targetEntity: File::class, mappedBy: 'documentWish', orphanRemoval: true)]
    private Collection $files;

    #[ORM\OneToOne(inversedBy: 'documentRib', targetEntity: AccessWish::class, cascade: [])]
    protected ?AccessWish $accessWishRib;

    #[ORM\OneToOne(inversedBy: 'documentSepa', targetEntity: AccessWish::class, cascade: [])]
    protected ?AccessWish $accessWishSepa;

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

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

    public function getAccessWish(): ?AccessWish
    {
        return $this->accessWish;
    }

    public function setAccessWish(?AccessWish $accessWish): self
    {
        $this->accessWish = $accessWish;

        return $this;
    }

    public function getPersonOwner(): ?Person
    {
        return $this->personOwner;
    }

    public function setPersonOwner(?Person $personOwner): self
    {
        $this->personOwner = $personOwner;

        return $this;
    }

    /**
     * @return Collection<int, File>
     */
    public function getFiles(): Collection
    {
        return $this->files;
    }

    public function addFile(File $file): self
    {
        if (!$this->files->contains($file)) {
            $this->files[] = $file;
            $file->setDocumentWish($this);
        }

        return $this;
    }

    public function removeFile(File $file): self
    {
        if ($this->files->removeElement($file)) {
            // set the owning side to null (unless already changed)
            if ($file->getDocumentWish() === $this) {
                $file->setDocumentWish(null);
            }
        }

        return $this;
    }

    public function getAccessWishRib(): AccessWish
    {
        return $this->accessWishRib;
    }

    public function setAccessWishRib(AccessWish $accessWishRib): self
    {
        $this->accessWishRib = $accessWishRib;

        return $this;
    }

    public function getAccessWishSepa(): AccessWish
    {
        return $this->accessWishSepa;
    }

    public function setAccessWishSepa(AccessWish $accessWishSepa): self
    {
        $this->accessWishSepa = $accessWishSepa;

        return $this;
    }
}
