<?php

namespace AppBundle\Entity\Booking;

use AppBundle\Annotation\DefaultField;
use AppBundle\Annotation\ExportSplitFields;
use AppBundle\Entity\Traits\ActivityYearTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Entity\Traits\TimestampableEntity;
use AppBundle\Entity\Traits\CreatorUpdaterEntity;

/**
 * Représente l'absence d'un Access à un type de Booking et à une date précise
 */
#[ORM\Entity(repositoryClass: 'AppBundle\Entity\Booking\Repository\AttendanceBookingRepository')]
class AttendanceBooking implements IAttendance
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    use ActivityYearTrait;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['attendancebooking', 'access_details', 'attendancebooking_list', 'planning_list', 'report_card', 'presence_attendance', 'planning_detail', 'booking_event', 'course_details', 'examen_details', 'educationalproject_details', 'event_details', 'access_attendance_detail'])]
    private $id;
    /**
     * @var Access
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'attendanceBookings')]
    #[Groups(['attendancebooking', 'attendancebooking_list', 'planning_list', 'presence_attendance_attendancebooking', 'planning_detail_attendancebooking', 'booking_event_attendancebooking', 'course_details_attendancebooking', 'examen_details_attendancebooking', 'educationalproject_details_attendancebooking', 'event_details_attendancebooking'])]
    private $access;
    /**
     * @var Attendance
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Booking\Attendance', inversedBy: 'attendanceBooking')]
    #[Groups(['attendancebooking', 'access_details_attendancebookingsfiltered', 'planning_detail_attendancebooking', 'booking_event_attendancebooking'])]
    private $attendance;
    /**
     * @var Course
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Booking\Course', inversedBy: 'attendanceBooking')]
    #[Groups(['access_details_attendancebookingsfiltered', 'attendancebooking', 'attendancebooking_list', 'my_attendance_list', 'planning_list', 'report_card_attendancebookings', 'access_attendance_detail_attendancebookings'])]
    private $course;
    /**
     * @var EducationalProject
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Booking\EducationalProject', inversedBy: 'attendanceBooking')]
    #[Groups(['access_details_attendancebookingsfiltered', 'attendancebooking', 'attendancebooking_list', 'my_attendance_list', 'planning_list', 'report_card_attendancebookings', 'access_attendance_detail_attendancebookings'])]
    private $educationalProject;
    /**
     * @var Event
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Booking\Event', inversedBy: 'attendanceBooking')]
    #[Groups(['access_details_attendancebookingsfiltered', 'attendancebooking', 'attendancebooking_list', 'my_attendance_list', 'planning_list', 'report_card_attendancebookings', 'access_attendance_detail_attendancebookings'])]
    private $event;
    /**
     * @var Examen
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Booking\Examen', inversedBy: 'attendanceBooking')]
    #[Groups(['access_details_attendancebookingsfiltered', 'attendancebooking', 'attendancebooking_list', 'my_attendance_list', 'planning_list', 'report_card_attendancebookings', 'access_attendance_detail_attendancebookings'])]
    private $examen;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'datetime', nullable: true)]
    #[Assert\DateTime]
    #[Groups(['access_details_attendancebookingsfiltered', 'attendancebooking', 'attendancebooking_list', 'my_attendance_list', 'planning_list', 'report_card_attendancebookings', 'presence_attendance_attendancebooking', 'planning_detail_attendancebooking', 'booking_event_attendancebooking', 'course_details_attendancebooking', 'examen_details_attendancebooking', 'educationalproject_details_attendancebooking', 'event_details_attendancebooking', 'access_attendance_detail_attendancebookings'])]
    private $datetimeStart;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'datetime', nullable: true)]
    #[Assert\DateTime]
    #[Groups(['access_details_attendancebookingsfiltered', 'attendancebooking', 'attendancebooking_list', 'my_attendance_list', 'planning_list', 'presence_attendance_attendancebooking', 'booking_event_attendancebooking', 'report_card_attendancebookings', 'access_attendance_detail_attendancebookings'])]
    private $datetimeEnd;
    /**
     * @var bool
     */
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[ORM\Column(type: 'boolean', options: ['default' => true])]
    #[Groups(['attendancebooking', 'access_details_attendancebookingsfiltered', 'attendancebooking_list', 'my_attendance_list', 'presence_attendance_attendancebooking', 'booking_event_attendancebooking', 'report_card_attendancebookings', 'access_attendance_detail_attendancebookings'])]
    private $justify = false;
    /**
     * @var string
     * @ExportSplitFields({"course.name','educationalProject.name','event.name','examen.name','course.organizer.person.fullNameTemplate"})
     */
    #[Groups(['template', 'attendancebooking_list'])]
    private $reservationTemplate;
    /**
     * Sets id.
     *
     * @param int $id
     *
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }
    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Set datetimeStart
     *
     * @param \DateTime $datetimeStart
     *
     * @return AttendanceBooking
     */
    public function setDatetimeStart(\DateTime $datetimeStart = null)
    {
        $this->datetimeStart = $datetimeStart;

        return $this;
    }
    /**
     * Get datetimeStart
     *
     * @return \DateTime
     */
    public function getDatetimeStart()
    {
        return $this->datetimeStart;
    }
    /**
     * Set datetimeEnd
     *
     * @param \DateTime $datetimeEnd
     *
     * @return AttendanceBooking
     */
    public function setDatetimeEnd(\DateTime $datetimeEnd = null)
    {
        $this->datetimeEnd = $datetimeEnd;

        return $this;
    }
    /**
     * Get datetimeEnd
     *
     * @return \DateTime
     */
    public function getDatetimeEnd()
    {
        return $this->datetimeEnd;
    }
    /**
     * Set attendance
     *
     * @param \AppBundle\Entity\Booking\Attendance $attendance
     *
     * @return AttendanceBooking
     */
    public function setAttendance(\AppBundle\Entity\Booking\Attendance $attendance = null)
    {
        $this->attendance = $attendance;

        return $this;
    }
    /**
     * Get attendance
     *
     * @return \AppBundle\Entity\Booking\Attendance
     */
    public function getAttendance()
    {
        return $this->attendance;
    }
    /**
     * Set access
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $access
     *
     * @return Attendance
     */
    public function setAccess(\AppBundle\Entity\AccessAndFunction\Access $access = null)
    {
        $this->access = $access;

        return $this;
    }
    /**
     * Get access
     *
     * @return \AppBundle\Entity\AccessAndFunction\Access
     */
    public function getAccess()
    {
        return $this->access;
    }
    /**
     * Set course
     *
     * @param \AppBundle\Entity\Booking\Course $course
     *
     * @return AttendanceBooking
     */
    public function setCourse(\AppBundle\Entity\Booking\Course $course = null)
    {
        $this->course = $course;

        return $this;
    }
    /**
     * Get course
     *
     * @return \AppBundle\Entity\Booking\Course
     */
    public function getCourse()
    {
        return $this->course;
    }
    /**
     * Set educationalProject
     *
     * @param \AppBundle\Entity\Booking\EducationalProject $educationalProject
     *
     * @return AttendanceBooking
     */
    public function setEducationalProject(\AppBundle\Entity\Booking\EducationalProject $educationalProject = null)
    {
        $this->educationalProject = $educationalProject;

        return $this;
    }
    /**
     * Get educationalProject
     *
     * @return \AppBundle\Entity\Booking\EducationalProject
     */
    public function getEducationalProject()
    {
        return $this->educationalProject;
    }
    /**
     * Set event
     *
     * @param \AppBundle\Entity\Booking\Event $event
     *
     * @return AttendanceBooking
     */
    public function setEvent(\AppBundle\Entity\Booking\Event $event = null)
    {
        $this->event = $event;

        return $this;
    }
    /**
     * Get event
     *
     * @return \AppBundle\Entity\Booking\Event
     */
    public function getEvent()
    {
        return $this->event;
    }
    /**
     * Set examen
     *
     * @param \AppBundle\Entity\Booking\Examen $examen
     *
     * @return AttendanceBooking
     */
    public function setExamen(\AppBundle\Entity\Booking\Examen $examen = null)
    {
        $this->examen = $examen;

        return $this;
    }
    /**
     * Get examen
     *
     * @return \AppBundle\Entity\Booking\Examen
     */
    public function getExamen()
    {
        return $this->examen;
    }
    /**
     * Set justify
     *
     * @param boolean $justify
     *
     * @return AttendanceBooking
     */
    public function setJustify($justify)
    {
        $this->justify = $justify;

        return $this;
    }
    /**
     * Get justify
     *
     * @return boolean
     */
    public function getJustify()
    {
        return $this->justify;
    }
    /**
     * Gets full label.
     *
     * @return array
     */
    public function getReservationTemplate()
    {

        $fullLabelTemplate = [];

        if(!empty($this->getCourse())){
            $fullLabelTemplate[] = $this->getCourse()->getName();
            $fullLabelTemplate[] = $this->getCourse()->getOrganizersTemplate();
        }
        if(!empty($this->getEducationalProject())){
            $fullLabelTemplate[] = $this->getEducationalProject()->getName();
        }
        if(!empty($this->getEvent())){
            $fullLabelTemplate[] = $this->getEvent()->getName();
        }
        if(!empty($this->getExamen())){
            $fullLabelTemplate[] = $this->getExamen()->getName();
        }

        return $fullLabelTemplate;
    }
}
