<?php

namespace AppBundle\Entity\Booking;

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

/**
 *
 * Travail à faire pour un cours
 *
 * @Iri("http://schema.org/Work")
 */
#[ORM\Entity]
class Work
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['work', 'worksbyusers_db'])]
    private $id;
    /**
     * @var Course
     */
    #[ORM\ManyToOne(targetEntity: 'Course', inversedBy: 'work')]
    #[Groups(['work', 'worksbyusers_db_work'])]
    private $course;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'datetime')]
    #[Assert\DateTime]
    #[Assert\NotNull]
    #[Groups(['work', 'worksbyusers_db_work'])]
    private $datetime;
    /**
     * @var string
     */
    #[ORM\Column(type: 'text', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['work', 'worksbyusers_db_work'])]
    private $work;
    /**
     * @var ArrayCollection<WorkByUser>
     */
    #[Assert\Valid]
    #[ORM\OneToMany(targetEntity: 'WorkByUser', mappedBy: 'work', cascade: ['persist'], orphanRemoval: true)]
    #[Groups(['work'])]
    private $workByUsers;
    /**
     * @var ArrayCollection<AppBundle\Entity\Core\File>.
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Core\File', mappedBy: 'work', orphanRemoval: true)]
    #[Groups(['work', 'worksbyusers_db_work'])]
    private $files;
    public function __construct()
    {
        $this->workByUsers = new ArrayCollection();
        $this->files = 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 course.
     *
     * @param Course $course
     *
     * @return $this
     */
    public function setCourse(Course $course = null)
    {
        $this->course = $course;

        return $this;
    }
    /**
     * Gets course.
     *
     * @return Course
     */
    public function getCourse()
    {
        return $this->course;
    }
    /**
     * Sets datetime.
     *
     * @param \DateTime $datetime
     *
     * @return $this
     */
    public function setDatetime(\DateTime $datetime)
    {
        $datetime->setTime($datetime->format("H"), $datetime->format("i"), 0);
        $datetime->setTimezone(new \DateTimeZone('UTC'));
        $this->datetime = $datetime;

        return $this;
    }
    /**
     * Gets datetime.
     *
     * @return \DateTime
     */
    public function getDatetime()
    {
        return $this->datetime;
    }
    /**
     * Sets works.
     *
     * @param string $work
     *
     * @return $this
     */
    public function setWork($work)
    {
        $this->work = $work;

        return $this;
    }
    /**
     * Gets work.
     *
     * @return string
     */
    public function getWork()
    {
        return $this->work;
    }
    /**
     * Add work By User
     *
     * @param WorkByUser $workByUSer
     *
     * @return Work
     */
    public function addWorkByUser(WorkByUser $workByUSer)
    {
        $workByUSer->setWork($this);
        $this->workByUsers[] = $workByUSer;
        return $this;
    }
    /**
     * Remove work By User
     *
     * @param WorkByUser $workByUSer
     */
    public function removeWorkByUser(WorkByUser $workByUSer)
    {
        $this->workByUsers->removeElement($workByUSer);
    }
    /**
     * Get work By User
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getWorkByUsers()
    {
        return $this->workByUsers;
    }
    /**
     * Add file
     *
     * @param \AppBundle\Entity\Core\File $file
     *
     * @return Work
     */
    public function addFile(\AppBundle\Entity\Core\File $file)
    {
        $file->setWork($this);
        $this->files[] = $file;

        return $this;
    }
    /**
     * Remove file
     *
     * @param \AppBundle\Entity\Core\File $file
     */
    public function removeFile(\AppBundle\Entity\Core\File $file)
    {
        $this->files->removeElement($file);
    }
    /**
     * Get files
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getFiles()
    {
        return $this->files;
    }
}
