<?php
declare (strict_types=1);

namespace App\Entity\Education;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Core\Tagg;
use App\Repository\Education\EducationNotationRepository;
//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.getEducationStudent().getAccess().getOrganization().getId() == user.getOrganization().getId()'
        )
    ]
)]
//#[Auditable]
#[ORM\Entity(repositoryClass: EducationNotationRepository::class)]
class EducationNotation
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'educationNotations')]
    #[ORM\JoinColumn(nullable: false)]
    private EducationStudent $educationStudent;

    #[ORM\ManyToOne(inversedBy: 'educationNotations')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private ?CriteriaNotation $criteriaNotation;

    #[ORM\ManyToOne(inversedBy: 'educationNotations')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private ?EducationNotationCriteriaConfig $criteriaNotationConfig;

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

    #[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
    #[Assert\Range(notInRangeMessage: 'between_{{ min }}_and_{{ max }}', min: 0, max: 100)]
    private ?float $note;

    public function __construct()
    {
        $this->tags = new ArrayCollection();
    }
    public function getId() : ?int
    {
        return $this->id;
    }
    public function getEducationStudent() : ?EducationStudent
    {
        return $this->educationStudent;
    }
    public function setEducationStudent(?EducationStudent $educationStudent) : self
    {
        $this->educationStudent = $educationStudent;
        return $this;
    }
    public function getCriteriaNotation() : ?CriteriaNotation
    {
        return $this->criteriaNotation;
    }
    public function setCriteriaNotation(?CriteriaNotation $criteriaNotation) : self
    {
        $this->criteriaNotation = $criteriaNotation;
        return $this;
    }
    public function getCriteriaNotationConfig() : ?EducationNotationCriteriaConfig
    {
        return $this->criteriaNotationConfig;
    }
    public function setCriteriaNotationConfig(?EducationNotationCriteriaConfig $criteriaNotationConfig) : self
    {
        $this->criteriaNotationConfig = $criteriaNotationConfig;
        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 setNote(?float $note) : self
    {
        $this->note = !is_null($note) ? (float) $note : $note;
        return $this;
    }
    public function getNote() : ?float
    {
        if (is_null($this->note)) {
            return $this->note;
        }
        return round($this->note, 2);
    }
}