<?php

namespace AppBundle\Entity\Education;

use AppBundle\Annotation\EntityJson;
use AppBundle\Annotation\ExportSplitFields;
use AppBundle\Entity\Booking\Examen;
use AppBundle\Enum\Education\PratiqueEnum;
use AppBundle\Enum\Product\ProductGroupEnum;
use AppBundle\Entity\Organization\Organization;
use AppBundle\Enum\Core\YearEnum;
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;

/**
 * Curriculum éducatif; composé d'un cycle, d'une année et d'un niveau
 *
 * @Iri("http://schema.org/EducationCurriculum")
 */
#[ORM\Entity(repositoryClass: 'AppBundle\Entity\Education\Repository\EducationCurriculumRepository')]
class EducationCurriculum
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    #[Assert\Type(type: 'string')]
    private $legacyId;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['educationcurriculum', 'intangible_list', 'my_student_list', 'planning_list', 'access_details_practicalcourses', 'presence_attendance', 'planning_detail', 'examen_details', 'course_details', 'educationstudent_reference', 'edu_stu_courses_courses', 'student_registration_courses', 'education_edit', 'examenconvocation_list_student', 'education_student_next_year', 'education_input_list', 'educationstudent_notation', 'educations_quotas_stats'])]
    private $id;
    /**
     * @var Education education
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Education\Education', inversedBy: 'educationCurriculums')]
    #[Assert\NotNull]
    #[Groups(['educationcurriculum', 'access_details_educationstudent', 'educationcurriculum_reference', 'student_list_educationstudent', 'student_list_courses', 'intangible_list_educationcurriculums', 'my_student_list_educationcurriculum', 'report_card_educationstudent', 'access_details_practicalcourses', 'educationstudent_reference_educationcurriculum', 'educationstudent_notation_educationcurriculum', 'educationcurriculum_reference', 'edu_stu_courses_courses', 'student_registration_courses', 'educationnotation_list_educationstudent', 'examenconvocation_list_student', 'accesses_courseteacher_show_practicalcourses', 'education_input_list_educationcurriculum', 'education_student_next_year_educationcurriculum', 'education_student_next_year_educationstudentlastyear', 'online_registration_access_details_educationstudent', 'access_intangible_list_intangible', 'accesses_no_reregistred_list_educationstudent'])]
    private $education;
    /**
     * @var string
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Education\Cycle')]
    #[Groups(['educationcurriculum', 'educationcurriculum_reference', 'access_details_educationstudent', 'student_list_educationstudent', 'intangible_list_educationcurriculums', 'my_student_list_educationcurriculum', 'planning_list', 'attendancebooking_list_course', 'generate_attendance', 'report_card_educationstudent', 'access_details_practicalcourses', 'presence_attendance_educationcurriculum', 'student_list_courses', 'examen_details_educationcurriculum', 'course_details_educationcurriculum', 'educationstudent_reference_educationcurriculum', 'edu_stu_courses_courses', 'student_registration_courses', 'educationnotation_list_educationstudent', 'education_edit_educationcurriculums', 'examenconvocation_list_examen', 'accesses_courseteacher_show_practicalcourses', 'education_student_next_year_educationcurriculum', 'education_student_next_year_educationstudentlastyear', 'education_input_list_educationcurriculum', 'access_intangible_list_intangible', 'worksbyusers_db_work', 'educationstudent_notation_educationcurriculum', 'accesses_no_reregistred_list_educationstudent'])]
    private $cycle;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Choice(callback: ['\AppBundle\Enum\Education\YearEnum', 'toArray'])]
    #[Groups(['educationcurriculum', 'educationcurriculum_reference', 'access_details_educationstudent', 'student_list_educationstudent', 'intangible_list_educationcurriculums', 'examenconvocation_list_examen', 'my_student_list_educationcurriculum', 'planning_list', 'attendancebooking_list_course', 'generate_attendance', 'report_card_educationstudent', 'access_details_practicalcourses', 'presence_attendance_educationcurriculum', 'student_list_courses', 'examen_details_educationcurriculum', 'course_details_educationcurriculum', 'educationstudent_reference_educationcurriculum', 'edu_stu_courses_courses', 'student_registration_courses', 'educationnotation_list_educationstudent', 'education_edit_educationcurriculums', 'accesses_courseteacher_show_practicalcourses', 'education_student_next_year_educationcurriculum', 'education_student_next_year_educationstudentlastyear', 'education_input_list_educationcurriculum', 'access_intangible_list_intangible', 'worksbyusers_db_work', 'educationstudent_notation_educationcurriculum', 'accesses_no_reregistred_list_educationstudent'])]
    private $year;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 25, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['educationcurriculum', 'educationcurriculum_reference', 'access_details_educationstudent', 'student_list_educationstudent', 'planning_list', 'report_card_educationstudent', 'access_details_practicalcourses', 'presence_attendance_educationcurriculum', 'student_list_courses', 'examen_details_educationcurriculum', 'course_details_educationcurriculum', 'educationstudent_reference_educationcurriculum', 'edu_stu_courses_courses', 'student_registration_courses', 'educationnotation_list_educationstudent', 'education_edit_educationcurriculums', 'examenconvocation_list_examen', 'accesses_courseteacher_show_practicalcourses', 'education_student_next_year_educationcurriculum', 'education_student_next_year_educationstudentlastyear', 'education_input_list_educationcurriculum', 'access_intangible_list_intangible', 'worksbyusers_db_work', 'educationstudent_notation_educationcurriculum', 'accesses_no_reregistred_list_educationstudent'])]
    private $level;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'date', nullable: true)]
    #[Assert\Date]
    #[Groups(['educationcurriculum'])]
    private $endDate;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['educationcurriculum', 'education_edit_educationcurriculums'])]
    private $isDisabled = false;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => true])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['educationcurriculum', 'education_edit_educationcurriculums'])]
    private $isActive = true;
    /**
     * @var integer
     */
    #[ORM\Column(type: 'integer', nullable: true)]
    #[Assert\Type(type: 'integer', message: 'invalid-integer')]
    #[Groups(['educationcurriculum'])]
    private $duration;
    /**
     * @var integer
     */
    #[ORM\Column(type: 'integer', nullable: true)]
    #[Assert\Type(type: 'integer', message: 'invalid-integer')]
    #[Groups(['educationcurriculum'])]
    private $nbStudentsMax;
    /**
     * @var integer
     */
    #[ORM\Column(type: 'integer', nullable: true)]
    #[Assert\Type(type: 'integer', message: 'invalid-integer')]
    #[Groups(['educationcurriculum'])]
    private $nbStudentsByCourse;
    /**
     * @var integer
     */
    #[ORM\Column(type: 'integer', nullable: true)]
    #[Assert\Type(type: 'integer', message: 'invalid-integer')]
    #[Groups(['educationcurriculum'])]
    private $packingRate;
    /**
     * @var ArrayCollection<EducationStudent>
     */
    #[ORM\OneToMany(targetEntity: 'EducationStudent', mappedBy: 'educationCurriculum', cascade: ['persist'])]
    #[Groups(['education_educationstudent'])]
    private $educationStudent;
    /**
     * @var integer
     */
    #[ORM\Column(type: 'integer', nullable: true)]
    #[Assert\Type(type: 'integer')]
    #[Groups(['education_edit_educationcurriculums', 'educationcurriculum', 'educations_quotas_stats_educationcurriculums'])]
    private $availablePlaces;
    /**
     * @var integer
     */
    #[Groups(['educations_quotas_stats_educationcurriculums'])]
    private $totalEducationStudents;
    /**
     * @var integer
     */
    #[Groups(['educations_quotas_stats_educationcurriculums'])]
    private $fillingRate;
    /**
     * @var integer
     */
    #[Groups(['educations_quotas_stats_educationcurriculums'])]
    private $order;
    /**
     * @var string
     * @ExportSplitFields({"education.educationCategory.label","education.educationComplementTemplate","cycle.label","year","level"})
     */
    #[Groups(['intangible_list_educationcurriculums', 'planning_detail_educationcurriculum', 'educationcurriculum', 'student_list_educationstudent', 'educationnotation_list_educationstudent', 'education_student_next_year_educationcurriculum', 'education_student_next_year_educationstudentlastyear', 'education_input_list_educationcurriculum', 'access_intangible_list_intangible', 'educations_quotas_stats_educationcurriculums'])]
    private $fullLabelTemplate;
    /**
     * @var string
     * @ExportSplitFields({"cycle.label","year","level"})
     */
    #[Groups(['examenconvocation_list_examen'])]
    private $cycleYearLevelTemplate;
    /**
     * Only for elasticsearch...
     * @var string
     */
    private $fullLabelElastic;
    /**
     * @var EducationNotationConfig
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Education\EducationNotationConfig', inversedBy: 'educationCurriculums')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    #[Groups(['educationcurriculum', 'educationcurriculum_reference'])]
    private $educationNotationConfig;

    #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Education\EducationTiming', inversedBy: 'educationCurriculums')]
    #[ORM\JoinTable(joinColumns: [], inverseJoinColumns: [])]
    #[ORM\JoinColumn(name: 'educationCurriculum_id', referencedColumnName: 'id')]
    #[ORM\JoinColumn(name: 'educationTiming_id', referencedColumnName: 'id')]
    #[Groups(['education_edit_educationcurriculums', 'educationcurriculum', 'educationcurriculum_reference'])]
    private $educationTimings;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->educationStudent = new ArrayCollection();
        $this->educationTimings = new ArrayCollection();
    }
    /**
     * Sets legacyId.
     *
     * @param string $legacyId
     *
     * @return $this
     */
    public function setLegacyId($legacyId)
    {
        $this->legacyId = $legacyId;

        return $this;
    }
    /**
     * Gets legacyId.
     *
     * @return string
     */
    public function getLegacyId()
    {
        return $this->legacyId;
    }
    /**
     * 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 education.
     *
     * @param Education $education
     *
     * @return $this
     */
    public function setEducation($education)
    {
        $this->education = $education;

        return $this;
    }
    /**
     * Gets education.
     *
     * @return Education
     */
    public function getEducation()
    {
        return $this->education;
    }
    /**
     * Sets cycle.
     *
     * @param string $cycle
     *
     * @return $this
     */
    public function setCycle($cycle)
    {
        $this->cycle = $cycle;

        return $this;
    }
    /**
     * Gets cycle.
     *
     * @return string
     */
    public function getCycle()
    {
        return $this->cycle;
    }
    /**
     * Sets year.
     *
     * @param integer $year
     *
     * @return $this
     */
    public function setYear($year)
    {
        $this->year = $year;

        return $this;
    }
    /**
     * Gets year.
     *
     * @return integer
     */
    public function getYear()
    {
        return $this->year;
    }
    /**
     * 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 endDate.
     *
     * @param \DateTime $endDate
     *
     * @return $this
     */
    public function setEndDate(\DateTime $endDate = null)
    {
        $this->endDate = $endDate;

        return $this;
    }
    /**
     * Gets endDate.
     *
     * @return \DateTime
     */
    public function getEndDate()
    {
        return $this->endDate ? $this->endDate->format('Y-m-d') : $this->endDate;
    }
    /**
     * Set isActive
     *
     * @param boolean $isActive
     *
     * @return CycleByNotation
     */
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;

        return $this;
    }
    /**
     * Get isActive
     *
     * @return boolean
     */
    public function getIsActive()
    {
        return $this->isActive;
    }
    /**
     * @param $isDisabled
     * @return $this
     */
    public function setIsDisabled($isDisabled)
    {
        $this->isDisabled = $isDisabled;

        return $this;
    }
    /**
     * @return bool
     */
    public function getIsDisabled()
    {
        return $this->isDisabled;
    }
    /**
     * Sets duration.
     *
     * @param integer $duration
     *
     * @return $this
     */
    public function setDuration($duration)
    {
        $this->duration = $duration;

        return $this;
    }
    /**
     * Gets duration.
     *
     * @return integer
     */
    public function getDuration()
    {
        return $this->duration;
    }
    /**
     * Sets nb students max.
     *
     * @param integer $nbStudentsMax
     *
     * @return $this
     */
    public function setNbStudentsMax($nbStudentsMax)
    {
        $this->nbStudentsMax = $nbStudentsMax;

        return $this;
    }
    /**
     * Gets nbStudentsMax.
     *
     * @return integer
     */
    public function getNbStudentsMax()
    {
        return $this->nbStudentsMax;
    }
    /**
     * Sets nbStudentsByCourse.
     *
     * @param integer $nbStudentsByCourse
     *
     * @return $this
     */
    public function setNbStudentsByCourse($nbStudentsByCourse)
    {
        $this->nbStudentsByCourse = $nbStudentsByCourse;

        return $this;
    }
    /**
     * Gets nbStudentsByCourse.
     *
     * @return integer
     */
    public function getNbStudentsByCourse()
    {
        return $this->nbStudentsByCourse;
    }
    /**
     * Gets packingRate.
     *
     * @return integer
     */
    public function getPackingRate()
    {
        return $this->packingRate;
    }
    /**
     * Set packingRate
     *
     * @param integer $packingRate
     *
     * @return EducationCurriculum
     */
    public function setPackingRate($packingRate)
    {
        $this->packingRate = $packingRate;

        return $this;
    }
    /**
     * Add educationStudent
     *
     * @param \AppBundle\Entity\Education\EducationStudent $educationStudent
     *
     * @return EducationCurriculum
     */
    public function addEducationStudent(\AppBundle\Entity\Education\EducationStudent $educationStudent)
    {
        $this->educationStudent[] = $educationStudent;

        return $this;
    }
    /**
     * Remove educationStudent
     *
     * @param \AppBundle\Entity\Education\EducationStudent $educationStudent
     */
    public function removeEducationStudent(\AppBundle\Entity\Education\EducationStudent $educationStudent)
    {
        $this->educationStudent->removeElement($educationStudent);
    }
    /**
     * Get educationStudent
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getEducationStudent()
    {
        return $this->educationStudent;
    }
    /**
     * Gets full label.
     *
     * @return array
     */
    public function getFullLabelTemplate()
    {
        return [
            $this->getEducation()->getEducationCategory()->getLabel(),
            $this->getEducation()->getEducationComplementTemplate(),
            $this->getCycle() && $this->getCycle()->getLabel() !== 'NO_CYCLE' ? $this->getCycle()->getLabel() : '',
            ['value' => $this->getYear(), 'translate' => true],
            $this->getLevel()
        ];
    }
    /**
     * Gets full label.
     *
     * @return array
     */
    public function getCycleYearLevelTemplate()
    {

        return [
            $this->getCycle() && $this->getCycle()->getLabel() !== 'NO_CYCLE' ? $this->getCycle()->getLabel() : '',
            ['value' => $this->getYear(), 'translate' => true],
            $this->getLevel()
        ];
    }
    /**
     * Gets full label.
     *
     * @return array
     */
    public function getFullLabelElastic()
    {

        return $this->getLevel();
    }
    /**
     * Set availablePlaces
     *
     * @param integer $availablePlaces
     *
     * @return EducationCurriculum
     */
    public function setAvailablePlaces($availablePlaces)
    {
        $this->availablePlaces = $availablePlaces;

        return $this;
    }
    /**
     * Get availablePlaces
     *
     * @return integer
     */
    public function getAvailablePlaces()
    {
        return $this->availablePlaces;
    }
    /**
     * Set totalEducationStudents
     *
     * @param integer $totalEducationStudents
     *
     * @return EducationCurriculum
     */
    public function setTotalEducationStudents($totalEducationStudents)
    {
        $this->totalEducationStudents = $totalEducationStudents;

        return $this;
    }
    /**
     * Get totalEducationStudents
     *
     * @return integer
     */
    public function getTotalEducationStudents()
    {
        return $this->totalEducationStudents;
    }
    /**
     * Set $fillingRate
     *
     * @param integer $fillingRate
     *
     * @return EducationCurriculum
     */
    public function setFillingRate($fillingRate)
    {
        $this->fillingRate = $fillingRate;

        return $this;
    }
    /**
     * Get $fillingRate
     *
     * @return integer
     */
    public function getFillingRate()
    {
        return $this->fillingRate;
    }
    /**
     * Set $order
     *
     * @param integer $order
     *
     * @return EducationCurriculum
     */
    public function setOrder($order)
    {
        $this->order = $order;

        return $this;
    }
    /**
     * Get $order
     *
     * @return integer
     */
    public function getOrder()
    {
        return $this->order;
    }
    /**
     * Sets educationNotationConfig.
     *
     * @param $educationNotationConfig
     *
     * @return $this
     */
    public function setEducationNotationConfig($educationNotationConfig)
    {
        $this->educationNotationConfig = $educationNotationConfig;

        return $this;
    }
    /**
     * Gets educationNotationConfig.
     *
     * @return EducationNotationConfig
     */
    public function getEducationNotationConfig()
    {
        return $this->educationNotationConfig;
    }
    /**
     * Add $educationTiming
     *
     * @param \AppBundle\Entity\Education\EducationTiming $educationTiming
     *
     * @return EducationCurriculum
     */
    public function addEducationTiming(\AppBundle\Entity\Education\EducationTiming $educationTiming)
    {
        $this->educationTimings[] = $educationTiming;

        return $this;
    }
    /**
     * Remove $educationTiming
     *
     * @param \AppBundle\Entity\Education\EducationTiming $educationTiming
     */
    public function removeEducationTiming(\AppBundle\Entity\Education\EducationTiming $educationTiming)
    {
        /** @var EducationStudent $educationStudent */
        foreach ($this->getEducationStudent() as $educationStudent){
            if($educationStudent->getEducationTiming() && $educationStudent->getEducationTiming()->getId() === $educationTiming->getId()){
                $educationStudent->setEducationTiming(null);
            }
        }
        $this->educationTimings->removeElement($educationTiming);
    }
    /**
     * Get EducationTiming
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getEducationTimings()
    {
        return $this->educationTimings;
    }
}
