<?php

namespace AppBundle\Entity\Booking;

use AppBundle\Annotation\DefaultField;
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 une période d'absence pour un Access dans une Organization
 */
#[ORM\Entity]
class Attendance implements IAttendance
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    use ActivityYearTrait;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['attendance', 'attendance_list'])]
    private $id;
    /**
     * @var Organization
     *
     * @DefaultField
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\Organization', inversedBy: 'attendances')]
    #[Groups(['attendance'])]
    private $organization;
    /**
     * @var Access
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'attendances')]
    #[Groups(['attendance', 'attendance_list'])]
    private $access;
    /**
     * @var Access
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'attendanceReplacements')]
    #[Groups(['attendance', 'attendance_list', 'planning_detail_attendancebooking'])]
    private $replacement;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'datetime', nullable: true)]
    #[Assert\DateTime]
    #[Groups(['attendance', 'attendance_list'])]
    private $datetimeStart;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'datetime', nullable: true)]
    #[Assert\DateTime]
    #[Groups(['attendance', 'attendance_list'])]
    private $datetimeEnd;
    /**
     * var ArrayCollection<AttendanceBooking>
     */
    #[Assert\Valid]
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Booking\AttendanceBooking', cascade: ['persist'], mappedBy: 'attendance', orphanRemoval: true)]
    #[ORM\JoinColumn(nullable: false)]
    #[Groups(['attendance_attendancebooking'])]
    private $attendanceBooking;
    public function __construct()
    {
        $this->attendanceBooking = new ArrayCollection();
    }
    /**
     * 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 Attendance
     */
    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 Attendance
     */
    public function setDatetimeEnd(\DateTime $datetimeEnd = null)
    {
        $this->datetimeEnd = $datetimeEnd;

        return $this;
    }
    /**
     * Get datetimeEnd
     *
     * @return \DateTime
     */
    public function getDatetimeEnd()
    {
        return $this->datetimeEnd;
    }
    /**
     * Set organization
     *
     * @param \AppBundle\Entity\Organization\Organization $organization
     *
     * @return Attendance
     */
    public function setOrganization(\AppBundle\Entity\Organization\Organization $organization = null)
    {
        $this->organization = $organization;

        return $this;
    }
    /**
     * Get organization
     *
     * @return \AppBundle\Entity\Organization\Organization
     */
    public function getOrganization()
    {
        return $this->organization;
    }
    /**
     * 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 replacement
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $replacement
     *
     * @return Attendance
     */
    public function setReplacement(\AppBundle\Entity\AccessAndFunction\Access $replacement = null)
    {
        $this->replacement = $replacement;

        return $this;
    }
    /**
     * Get replacement
     *
     * @return \AppBundle\Entity\AccessAndFunction\Access
     */
    public function getReplacement()
    {
        return $this->replacement;
    }
    /**
     * Add attendanceBooking
     *
     * @param \AppBundle\Entity\Booking\AttendanceBooking $attendanceBooking
     *
     * @return Attendance
     */
    public function addAttendanceBooking(\AppBundle\Entity\Booking\AttendanceBooking $attendanceBooking)
    {
        $attendanceBooking->setAttendance($this);
        $attendanceBooking->setAccess($this->getAccess());
        $this->attendanceBooking[] = $attendanceBooking;

        return $this;
    }
    /**
     * Remove attendanceBooking
     *
     * @param \AppBundle\Entity\Booking\AttendanceBooking $attendanceBooking
     */
    public function removeAttendanceBooking(\AppBundle\Entity\Booking\AttendanceBooking $attendanceBooking)
    {
        $this->attendanceBooking->removeElement($attendanceBooking);
    }
    /**
     * Get attendanceBooking
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getAttendanceBooking()
    {
        return $this->attendanceBooking;
    }
}
