<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;


/**
 * Document
 *
 * @ORM\Table(name="document")
 * @ORM\Entity(repositoryClass="App\Repository\DocumentRepository")
 * @Vich\Uploadable
 */
class Document
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(name="document", type="string", length=255, nullable=true)
     */
    private $document;

    /**
     * NOTE: This is not a mapped field of entity metadata, just a simple property.
     * 
     * @Vich\UploadableField(mapping="documents_competition", fileNameProperty="document")
     * 
     * @var File
     */
    private $documentFile;

     /**
     * @ORM\Column(type="datetime")
     *
     * @var \DateTime
     */
    private $updatedAt;


    /**
     * @var string
     *
     * @ORM\Column(name="url", type="string", length=255, nullable=true)
     */
    private $url;

    /**
     * @var string
     * @ORM\Column(name="type", type="string",columnDefinition="enum('DOCUMENTO','URL')", length=50)
     */
    private $type;

    /**
     * @var string
     * @ORM\Column(name="extension",  type="string", length=255, nullable=true)
     */
    private $extension;

    /**
     * @ORM\Column(type="integer")
     */
    private $position;

    /**
     * @ORM\Column(type="boolean")
     */
    private $public = 1;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $description;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Area", inversedBy="documents")
     * @ORM\JoinColumn(nullable=false)
     */
    private $area;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\UsersDocumentReference", mappedBy="document")
     */
    private $usersDocumentReferences;

    /**
     * @var string
     *
     * @ORM\Column(name="thumbnail", type="string", length=255, nullable=true)
     */
    private $thumbnail;

    /**
     * NOTE: This is not a mapped field of entity metadata, just a simple property.
     * 
     * @Vich\UploadableField(mapping="document_thumbnail", fileNameProperty="thumbnail")
     * 
     * @var File
     */
    private $thumbnailFile;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Competition", inversedBy="documents")
     * @ORM\JoinColumn(nullable=false)
     */
    private $competition;

    public function __construct()
    {
        $this->users = new ArrayCollection();
        $this->usersDocumentReferences = new ArrayCollection();
    }


    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set document
     *
     * @param document $document
     *
     * @return Document
     */
    public function setName($name)
    {
        $this->name = $name;
    
        return $this;
    }

    /**
     * Get string
     *
     * @return document
     */
    public function getName()
    {
        return $this->name;
    }

    public function setDocumentFile(File $document = null)
    {
        $this->documentFile = $document;

        // VERY IMPORTANT:
        // It is required that at least one field changes if you are using ,
        // otherwise the event listeners won't be called and the filDoctrinee is lost
        if ($document) {
            // if 'updatedAt' is not defined in your entity, use another property
            $this->updatedAt = new \DateTime('now');
        }
    }

    public function getDocumentFile()
    {
        return $this->documentFile;
    }

    public function setThumbnailFile(File $thumbnail = null)
    {
        $this->thumbnailFile = $thumbnail;

        // VERY IMPORTANT:
        // It is required that at least one field changes if you are using ,
        // otherwise the event listeners won't be called and the filDoctrinee is lost
        if ($thumbnail) {
            // if 'updatedAt' is not defined in your entity, use another property
            $this->updatedAt = new \DateTime('now');
        }
    }

    public function getThumbnailFile()
    {
        return $this->thumbnailFile;
    }

    
    public function setUpdatedAt($updatedAt){
        $this->updatedAt = $updatedAt;
    }

    public function getUpdatedAt(){
        return $this->updatedAt;
    }

    /**
     * Set document
     *
     * @param document $document
     *
     * @return Document
     */
    public function setDocument($document)
    {
        $this->document = $document;
    
        return $this;
    }

    /**
     * Get string
     *
     * @return document
     */
    public function getDocument()
    {
        return $this->document;
    }


    /**
     * Set url
     *
     * @param url $url
     *
     * @return Document
     */
    public function setUrl($url)
    {
        $this->url = $url;
    
        return $this;
    }

    /**
     * Get string
     *
     * @return url
     */
    public function getUrl()
    {
        return $this->url;
    }


    /**
     * Set type
     *
     * @param string $type
     *
     * @return Document
     */
    public function setType($type)
    {
        $this->type = $type;
    
        return $this;
    }

    /**
     * Get type
     *
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * Set type
     *
     * @param string $type
     *
     * @return Document
     */
    public function setExtension($extension)
    {
        $this->extension = $extension;
    
        return $this;
    }

    /**
     * Get type
     *
     * @return string
     */
    public function getExtension()
    {
        return $this->extension;
    }

    public function getPosition(): ?int
    {
        return $this->position;
    }

    public function setPosition(int $position): self
    {
        $this->position = $position;

        return $this;
    }

    public function getPublic(): ?int
    {
        return $this->public;
    }

    public function setPublic(int $public): self
    {
        $this->public = $public;

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(string $description): self
    {
        $this->description = $description;

        return $this;
    }

    public function getArea(): ?Area
    {
        return $this->area;
    }

    public function setArea(?Area $area): self
    {
        $this->area = $area;

        return $this;
    }

    /**
     * @return Collection|UsersDocumentReference[]
     */
    public function getUsersDocumentReferences(): Collection
    {
        return $this->usersDocumentReferences;
    }

    public function addUsersDocumentReference(UsersDocumentReference $usersDocumentReference): self
    {
        if (!$this->usersDocumentReferences->contains($usersDocumentReference)) {
            $this->usersDocumentReferences[] = $usersDocumentReference;
            $usersDocumentReference->setDocument($this);
        }

        return $this;
    }

    public function removeUsersDocumentReference(UsersDocumentReference $usersDocumentReference): self
    {
        if ($this->usersDocumentReferences->contains($usersDocumentReference)) {
            $this->usersDocumentReferences->removeElement($usersDocumentReference);
            // set the owning side to null (unless already changed)
            if ($usersDocumentReference->getDocument() === $this) {
                $usersDocumentReference->setDocument(null);
            }
        }

        return $this;
    }

    public function getThumbnail(): ?string
    {
        return $this->thumbnail;
    }

    public function setThumbnail(?string $thumbnail): self
    {
        $this->thumbnail = $thumbnail;

        return $this;
    }

    public function getCompetition(): ?Competition
    {
        return $this->competition;
    }

    public function setCompetition(?Competition $competition): self
    {
        $this->competition = $competition;

        return $this;
    }

}
