<?php
declare (strict_types=1);

namespace App\Entity\Education;

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

//use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Classe ... qui ...
 */
#[ApiResource(
    operations: [
        new Get(
            security: 'is_granted(\'ROLE_ADMIN\') and object.getOrganization().getId() == user.getOrganization().getId()'
        )
    ]
)]
//#[Auditable]
#[ORM\Entity]
class CriteriaNotation
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'critereNotations')]
    #[ORM\JoinColumn(nullable: false)]
    private Organization $organization;

    #[ORM\OneToMany(mappedBy: 'criteriaNotation', targetEntity: EducationNotation::class)]
    private Collection $educationNotations;

    #[ORM\OneToMany(mappedBy: 'criteriaNotation', targetEntity: CustomNotation::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
    private Collection $customNotation;

    #[ORM\OneToMany(mappedBy: 'criteriaNotation', targetEntity: EducationNotationCriteriaConfig::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
    private Collection $educationNotationCriteriaConfigs;

    #[ORM\Column]
    #[Assert\Choice(callback: ['\\App\\Enum\\Education\\TypeCriteriaEnum', 'toArray'], message: 'invalid-type')]
    private string $type;

    #[ORM\Column]
    #[Assert\GreaterThanOrEqual(value: 0)]
    #[Assert\Range(notInRangeMessage: 'between_{{ min }}_and_{{ max }}', min: 0, max: 100)]
    private ?int $noteMax;

    public function __construct()
    {
        $this->educationNotations = new ArrayCollection();
        $this->customNotation = new ArrayCollection();
        $this->educationNotationCriteriaConfigs = new ArrayCollection();
    }

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

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

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

    /**
     * @return Collection<int, EducationNotation>
     */
    public function getEducationNotations(): Collection
    {
        return $this->educationNotations;
    }

    public function addEducationNotation(EducationNotation $educationNotation): self
    {
        if (!$this->educationNotations->contains($educationNotation)) {
            $this->educationNotations[] = $educationNotation;
            $educationNotation->setCriteriaNotation($this);
        }
        return $this;
    }

    public function removeEducationNotation(EducationNotation $educationNotation): self
    {
        if ($this->educationNotations->removeElement($educationNotation)) {
            // set the owning side to null (unless already changed)
            if ($educationNotation->getCriteriaNotation() === $this) {
                $educationNotation->setCriteriaNotation(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, CustomNotation>
     */
    public function getCustomNotation(): Collection
    {
        return $this->customNotation;
    }

    public function addCustomNotation(CustomNotation $customNotation): self
    {
        if (!$this->customNotation->contains($customNotation)) {
            $this->customNotation[] = $customNotation;
            $customNotation->setCriteriaNotation($this);
        }
        return $this;
    }

    public function removeCustomNotation(CustomNotation $customNotation): self
    {
        if ($this->customNotation->removeElement($customNotation)) {
            // set the owning side to null (unless already changed)
            if ($customNotation->getCriteriaNotation() === $this) {
                $customNotation->setCriteriaNotation(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, EducationNotationCriteriaConfig>
     */
    public function getEducationNotationCriteriaConfigs(): Collection
    {
        return $this->educationNotationCriteriaConfigs;
    }

    public function addEducationNotationCriteriaConfig(EducationNotationCriteriaConfig $educationNotationCriteriaConfig): self
    {
        if (!$this->educationNotationCriteriaConfigs->contains($educationNotationCriteriaConfig)) {
            $this->educationNotationCriteriaConfigs[] = $educationNotationCriteriaConfig;
            $educationNotationCriteriaConfig->setCriteriaNotation($this);
        }
        return $this;
    }

    public function removeEducationNotationCriteriaConfig(EducationNotationCriteriaConfig $educationNotationCriteriaConfig): self
    {
        if ($this->educationNotationCriteriaConfigs->removeElement($educationNotationCriteriaConfig)) {
            // set the owning side to null (unless already changed)
            if ($educationNotationCriteriaConfig->getCriteriaNotation() === $this) {
                $educationNotationCriteriaConfig->setCriteriaNotation(null);
            }
        }
        return $this;
    }

    public function getType(): ?string
    {
        return $this->type;
    }

    public function setType(string $type): self
    {
        $this->type = $type;
        return $this;
    }

    public function getNoteMax(): ?int
    {
        return $this->noteMax;
    }

    public function setNoteMax(int $noteMax): self
    {
        $this->noteMax = $noteMax;
        return $this;
    }
}