<?php
declare (strict_types=1);

namespace App\Entity\Education;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Access\Access;

//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.getAccess().getOrganization().getId() == user.getOrganization().getId()'
        )
    ]
)]
//#[Auditable]
#[ORM\Entity]
class EducationTeacher
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'educationTeachers')]
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
    private Education $education;

    #[ORM\ManyToOne(inversedBy: 'educationTeachers')]
    private Access $teacher;

    #[ORM\OneToMany(mappedBy: 'educationTeacher', targetEntity: SeizurePeriodNotation::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
    private Collection $seizurePeriodNotations;

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

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

    public function getEducation(): ?Education
    {
        return $this->education;
    }

    public function setEducation(?Education $education): self
    {
        $this->education = $education;
        return $this;
    }

    public function getTeacher(): ?Access
    {
        return $this->teacher;
    }

    public function setTeacher(?Access $teacher): self
    {
        $this->teacher = $teacher;
        return $this;
    }

    /**
     * @return Collection<int, SeizurePeriodNotation>
     */
    public function getSeizurePeriodNotations(): Collection
    {
        return $this->seizurePeriodNotations;
    }

    public function addSeizurePeriodNotation(SeizurePeriodNotation $seizurePeriodNotation): self
    {
        if (!$this->seizurePeriodNotations->contains($seizurePeriodNotation)) {
            $this->seizurePeriodNotations[] = $seizurePeriodNotation;
            $seizurePeriodNotation->setEducationTeacher($this);
        }
        return $this;
    }

    public function removeSeizurePeriodNotation(SeizurePeriodNotation $seizurePeriodNotation): self
    {
        if ($this->seizurePeriodNotations->removeElement($seizurePeriodNotation)) {
            // set the owning side to null (unless already changed)
            if ($seizurePeriodNotation->getEducationTeacher() === $this) {
                $seizurePeriodNotation->setEducationTeacher(null);
            }
        }
        return $this;
    }
}