<?php
declare (strict_types=1);

namespace App\Entity\Education;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Booking\Course;
use App\Entity\Booking\Examen;
use App\Entity\Core\Tagg;

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

    #[ORM\OneToMany(mappedBy: 'education', targetEntity: EducationCurriculum::class, cascade: ['persist'], orphanRemoval: true)]
    private Collection $educationCurriculums;

    #[ORM\OneToMany(mappedBy: 'education', targetEntity: CycleByEducation::class, cascade: ['persist'], orphanRemoval: true)]
    private Collection $cycleByEducations;

    #[ORM\ManyToOne(fetch: 'EAGER', inversedBy: 'educations')]
    #[ORM\JoinColumn(nullable: false)]
    private EducationCategory $educationCategory;

    #[ORM\ManyToOne(fetch: 'EAGER')]
    #[ORM\JoinColumn(nullable: false)]
    private EducationComplement $educationComplement;

    #[ORM\OneToMany(mappedBy: 'education', targetEntity: Course::class)]
    private Collection $courses;

    #[ORM\OneToMany(mappedBy: 'education', targetEntity: Examen::class)]
    private Collection $examens;

    #[ORM\OneToMany(mappedBy: 'education', targetEntity: EducationTeacher::class, orphanRemoval: true)]
    private Collection $educationTeachers;

    #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'educations', cascade: ['persist'])]
    #[ORM\JoinTable(name: 'tag_education')]
    #[ORM\JoinColumn(name: 'education_id', referencedColumnName: 'id')]
    #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
    private Collection $tags;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private EducationNotationConfig $educationNotationConfig;

    public function __construct()
    {
        $this->educationCurriculums = new ArrayCollection();
        $this->cycleByEducations = new ArrayCollection();
        $this->courses = new ArrayCollection();
        $this->examens = new ArrayCollection();
        $this->educationTeachers = new ArrayCollection();
        $this->tags = new ArrayCollection();
    }

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

    /**
     * @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;
            $educationCurriculum->setEducation($this);
        }
        return $this;
    }

    public function removeEducationCurriculum(EducationCurriculum $educationCurriculum): self
    {
        if ($this->educationCurriculums->removeElement($educationCurriculum)) {
            // set the owning side to null (unless already changed)
            if ($educationCurriculum->getEducation() === $this) {
                $educationCurriculum->setEducation(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, CycleByEducation>
     */
    public function getCycleByEducations(): Collection
    {
        return $this->cycleByEducations;
    }

    public function addCycleByEducation(CycleByEducation $cycleByEducation): self
    {
        if (!$this->cycleByEducations->contains($cycleByEducation)) {
            $this->cycleByEducations[] = $cycleByEducation;
            $cycleByEducation->setEducation($this);
        }
        return $this;
    }

    public function removeCycleByEducation(CycleByEducation $cycleByEducation): self
    {
        if ($this->cycleByEducations->removeElement($cycleByEducation)) {
            // set the owning side to null (unless already changed)
            if ($cycleByEducation->getEducation() === $this) {
                $cycleByEducation->setEducation(null);
            }
        }
        return $this;
    }

    public function getEducationCategory(): ?EducationCategory
    {
        return $this->educationCategory;
    }

    public function setEducationCategory(?EducationCategory $educationCategory): self
    {
        $this->educationCategory = $educationCategory;
        return $this;
    }

    public function getEducationComplement(): ?EducationComplement
    {
        return $this->educationComplement;
    }

    public function setEducationComplement(?EducationComplement $educationComplement): self
    {
        $this->educationComplement = $educationComplement;
        return $this;
    }

    /**
     * @return Collection<int, Course>
     */
    public function getCourses(): Collection
    {
        return $this->courses;
    }

    public function addCourse(Course $course): self
    {
        if (!$this->courses->contains($course)) {
            $this->courses[] = $course;
            $course->setEducation($this);
        }
        return $this;
    }

    public function removeCourse(Course $course): self
    {
        if ($this->courses->removeElement($course)) {
            // set the owning side to null (unless already changed)
            if ($course->getEducation() === $this) {
                $course->setEducation(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, Examen>
     */
    public function getExamens(): Collection
    {
        return $this->examens;
    }

    public function addExamen(Examen $examen): self
    {
        if (!$this->examens->contains($examen)) {
            $this->examens[] = $examen;
            $examen->setEducation($this);
        }
        return $this;
    }

    public function removeExamen(Examen $examen): self
    {
        if ($this->examens->removeElement($examen)) {
            // set the owning side to null (unless already changed)
            if ($examen->getEducation() === $this) {
                $examen->setEducation(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, EducationTeacher>
     */
    public function getEducationTeachers(): Collection
    {
        return $this->educationTeachers;
    }

    public function addEducationTeacher(EducationTeacher $educationTeacher): self
    {
        if (!$this->educationTeachers->contains($educationTeacher)) {
            $this->educationTeachers[] = $educationTeacher;
            $educationTeacher->setEducation($this);
        }
        return $this;
    }

    public function removeEducationTeacher(EducationTeacher $educationTeacher): self
    {
        if ($this->educationTeachers->removeElement($educationTeacher)) {
            // set the owning side to null (unless already changed)
            if ($educationTeacher->getEducation() === $this) {
                $educationTeacher->setEducation(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, Tagg>
     */
    public function getTags(): Collection
    {
        return $this->tags;
    }

    public function addTag(Tagg $tag): self
    {
        if (!$this->tags->contains($tag)) {
            $this->tags[] = $tag;
        }
        return $this;
    }

    public function removeTag(Tagg $tag): self
    {
        $this->tags->removeElement($tag);
        return $this;
    }

    public function getEducationNotationConfig(): ?EducationNotationConfig
    {
        return $this->educationNotationConfig;
    }

    public function setEducationNotationConfig(?EducationNotationConfig $educationNotationConfig): self
    {
        $this->educationNotationConfig = $educationNotationConfig;
        return $this;
    }
}