<?php

namespace AppBundle\Entity\Booking;

use AppBundle\Annotation\ExportSplitFields;
use AppBundle\Entity\AccessAndFunction\Access;
use AppBundle\Entity\Product\Equipment;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Dunglas\ApiBundle\Annotation\Iri;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Entity\Traits\TimestampableEntity;
use AppBundle\Entity\Traits\CreatorUpdaterEntity;
use AppBundle\Entity\Person\Person;

/**
 *
 * Convocation d'un Access (élève) à un Examen
 *
 * @Iri("http://schema.org/ExamenConvocation")
 */
#[ORM\Entity]
class ExamenConvocation
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'report_card', 'presence_attendance', 'examen_details', 'planning_detail', 'examen_informations_edit'])]
    private $id;
    /**
     * @var Examen
     */
    #[ORM\ManyToOne(targetEntity: 'Examen', inversedBy: 'convocation')]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'report_card_examenconvocations'])]
    private $examen;
    /**
     * @var Access
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'examenConvocations')]
    #[ORM\JoinColumn(nullable: false)]
    #[Assert\NotNull]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'presence_attendance_convocation', 'examen_details_convocation', 'planning_detail_convocation', 'examenconvocation_list', 'examen_informations_edit_convocation', 'examenconvocation_list'])]
    private $student;
    /**
     * @var ArrayCollection<Equipment>
     */
    #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Product\Equipment')]
    #[ORM\JoinTable(joinColumns: [], inverseJoinColumns: [])]
    #[ORM\JoinColumn(name: 'examenconvocation_id', referencedColumnName: 'id')]
    #[ORM\JoinColumn(name: 'equipment_id', referencedColumnName: 'id')]
    #[Groups(['examenconvocation_equipment', 'examenconvocation_list', 'examen_informations_edit_convocation'])]
    private $equipments;
    /**
     * @var string
     */
    #[ORM\Column(type: 'text', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'examen_informations_edit_convocation'])]
    private $info;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'examen_informations_edit_convocation'])]
    private $level;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'time', nullable: true)]
    #[Assert\Time]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'examen_details_convocation', 'examen_informations_edit_convocation'])]
    private $time;
    /**
     * @var float
     */
    #[ORM\Column(type: 'float', nullable: true)]
    #[Assert\Type(type: 'float')]
    #[Assert\GreaterThanOrEqual(value: 0)]
    #[Assert\LessThanOrEqual(value: 100, message: 'lessThanOrEqual20')]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'report_card_examenconvocations', 'examen_informations_edit_convocation'])]
    private $note;
    /**
     * @var string
     */
    #[Groups(['examenconvocation', 'examenconvocation_list'])]
    private $noteTemplate;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'report_card_examenconvocations', 'examen_informations_edit_convocation'])]
    private $mention;
    /**
     * @var string
     */
    #[ORM\Column(type: 'text', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'report_card_examenconvocations', 'examen_informations_edit_convocation'])]
    private $appreciation;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 255)]
    #[Assert\Type(type: 'string')]
    #[Assert\NotNull]
    #[Assert\Choice(callback: ['\AppBundle\Enum\Booking\ExamenConvocationStatusEnum', 'toArray'])]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'examen_informations_edit_convocation'])]
    private $status;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['examenconvocation', 'examenconvocation_list', 'examen_informations_edit_convocation'])]
    private $isConvocated = false;
    /**
     * @var string
     */
    #[Groups(['examenconvocation_list', 'report_card_examenconvocations'])]
    private $cycleYearLevelStudentTemplate;
    public function __construct()
    {
        $this->equipments = new ArrayCollection();
    }
    /**
     * Sets id.
     * 
     * @param int $id
     * 
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }
    /**
     * Gets id.
     * 
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Sets examen.
     * 
     * @param Examen $examen
     * 
     * @return $this
     */
    public function setExamen(Examen $examen)
    {
        $this->examen = $examen;

        return $this;
    }
    /**
     * Gets examen.
     * 
     * @return Examen
     */
    public function getExamen()
    {
        return $this->examen;
    }
    /**
     * Sets student.
     * 
     * @param Access $student
     * 
     * @return $this
     */
    public function setStudent(Access $student)
    {
        $this->student = $student;

        return $this;
    }
    /**
     * Gets student.
     * 
     * @return Access
     */
    public function getStudent()
    {
        return $this->student;
    }
    /**
     * Sets info.
     * 
     * @param string $info
     * 
     * @return $this
     */
    public function setInfo($info)
    {
        $this->info = $info;

        return $this;
    }
    /**
     * Gets info.
     * 
     * @return string
     */
    public function getInfo()
    {
        return $this->info;
    }
    /**
     * Sets level.
     * 
     * @param string $level
     * 
     * @return $this
     */
    public function setLevel($level)
    {
        $this->level = $level;

        return $this;
    }
    /**
     * Gets level.
     * 
     * @return string
     */
    public function getLevel()
    {
        return $this->level;
    }
    /**
     * Sets time.
     * 
     * @param \DateTime $time
     * 
     * @return $this
     */
    public function setTime(\DateTime $time = null)
    {
        $this->time = $time;

        return $this;
    }
    /**
     * Gets time.
     * 
     * @return \DateTime
     */
    public function getTime()
    {
        return $this->time ? $this->time->format('H:i') : $this->time;
    }
    /**
     * Sets note.
     * 
     * @param float $note
     * 
     * @return $this
     */
    public function setNote($note)
    {
        $this->note = (!is_null($note)) ? floatval($note) : $note;

        return $this;
    }
    /**
     * Gets note.
     * 
     * @return float
     */
    public function getNote()
    {
        return $this->note;
    }
    /**
     * Sets mention.
     * 
     * @param string $mention
     * 
     * @return $this
     */
    public function setMention($mention)
    {
        $this->mention = $mention;

        return $this;
    }
    /**
     * Gets mention.
     * 
     * @return string
     */
    public function getMention()
    {
        return $this->mention;
    }
    /**
     * Sets appreciation.
     * 
     * @param string $appreciation
     * 
     * @return $this
     */
    public function setAppreciation($appreciation)
    {
        $this->appreciation = $appreciation;

        return $this;
    }
    /**
     * Gets appreciation.
     * 
     * @return string
     */
    public function getAppreciation()
    {
        return $this->appreciation;
    }
    /**
     * Sets status.
     * 
     * @param string $status
     * 
     * @return $this
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }
    /**
     * Gets status.
     * 
     * @return string
     */
    public function getStatus()
    {
        return $this->status;
    }
    /**
     * Add equipment
     *
     * @param \AppBundle\Entity\Product\Equipment $equipment
     *
     * @return ExamenConvocation
     */
    public function addEquipment(\AppBundle\Entity\Product\Equipment $equipment)
    {
        $this->equipments[] = $equipment;

        return $this;
    }
    /**
     * Remove equipment
     *
     * @param \AppBundle\Entity\Product\Equipment $equipment
     */
    public function removeEquipment(\AppBundle\Entity\Product\Equipment $equipment)
    {
        $this->equipments->removeElement($equipment);
    }
    /**
     * Get equipments
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getEquipments()
    {
        return $this->equipments;
    }
    /**
     * Sets isConvocated.
     *
     * @param bool $isConvocated
     *
     * @return $this
     */
    public function setIsConvocated($isConvocated)
    {
        $this->isConvocated = $isConvocated;

        return $this;
    }
    /**
     * Gets isConvocated.
     *
     * @return bool
     */
    public function getIsConvocated()
    {
        return $this->isConvocated;
    }
    /**
     * @return float
     */
    public function getNoteTemplate()
    {
        return (!is_null($this->getNote())) ? floatval($this->getNote() / 5) : $this->getNote();
    }
    /**
     * Gets full label.
     *
     * @return array
     */
    public function getCycleYearLevelStudentTemplate()
    {
        $cycleYearLevelStudent = '';
        foreach($this->getExamen()->getEducationCurriculum() as $educationCurriculum){
            foreach($this->getStudent()->getEducationStudent() as $educationStudent){
                if(!is_null($educationCurriculum) && !is_null($educationStudent->getEducationCurriculum()) && $educationCurriculum->getId() === $educationStudent->getEducationCurriculum()->getId()){
                    $cycleYearLevelStudent = $educationCurriculum->getCycleYearLevelTemplate();
                    break;
                }
            }
        }
        return $cycleYearLevelStudent;
    }
}
