<?php

namespace AppBundle\Entity\Core;

use AppBundle\AppBundle;
use AppBundle\Entity\AccessWish\DocumentWish;
use AppBundle\Entity\Booking\CalendarSynchro;
use AppBundle\Entity\Booking\EventReport;
use AppBundle\Entity\Message\TemplateSystem;
use AppBundle\Entity\Organization\Organization;
use AppBundle\Entity\Organization\Parameters;
use AppBundle\Entity\Person\Person;
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;
use Symfony\Component\Validator\Context\ExecutionContextInterface;

/**
 * Tout type de fichier associé à un Access ou une Organization
 *
 * @Iri("http://schema.org/File")
 */
#[ORM\Entity(repositoryClass: 'AppBundle\Entity\Core\Repository\FileRepository')]
#[ORM\Table(name: 'File')]
#[ORM\Index(name: 'visibility', columns: ['visibility'])]
#[ORM\Index(name: 'folder', columns: ['folder'])]
class File
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['file', 'report_card', 'email_detail', 'access_details_person', 'organization_details', 'booking_event_documents', 'event_details', 'student_registration_person', 'onlineregistration_infos', 'worksbyusers_db_work'])]
    private $id;
    /**
     * @var string
     *
     *
     */
    #[ORM\Column(type: 'string', length: 255)]
    #[Assert\Type(type: 'string')]
    #[Assert\NotNull]
    private $slug;
    /**
     * @var string
     *
     *
     */
    #[ORM\Column(type: 'string', length: 255)]
    #[Assert\Type(type: 'string')]
    #[Assert\NotNull]
    private $path;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 255)]
    #[Assert\Type(type: 'string')]
    #[Assert\NotNull]
    #[Groups(['file', 'report_card', 'access_details_person', 'booking_event_documents_files', 'event_details_files', 'event_details_eventreports', 'my_bills_show_bills', 'access_files_person', 'email_detail_files', 'student_registration_person', 'onlineregistration_infos_introductionfiles', 'onlineregistration_infos_introductionfilesnewenrolments', 'worksbyusers_db_work'])]
    private $name;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['file'])]
    private $mimeType;
    /**
     * @var Person
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Person\Person', inversedBy: 'files')]
    #[ORM\JoinColumn(name: 'person_id', referencedColumnName: 'id')]
    #[Groups(['file', 'booking_event_documents_files'])]
    private $person;
    /**
     * @var Organization
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\Organization', inversedBy: 'files')]
    #[ORM\JoinColumn(name: 'organization_id', referencedColumnName: 'id')]
    #[Groups(['file', 'booking_event_documents_files', 'email_detail_files'])]
    private $organization;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string')]
    #[Assert\Type(type: 'string')]
    #[Assert\NotNull]
    #[Assert\Choice(callback: ['\AppBundle\Enum\Core\FileVisibilityEnum', 'toArray'])]
    #[Groups(['file'])]
    private $visibility;
    /**
     * @var array
     */
    #[ORM\Column(type: 'json_array', nullable: true)]
    #[Groups(['file'])]
    private $accessRoles;
    /**
     * @var ArrayCollection<Person>
     */
    #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Person\Person', inversedBy: 'personFiles')]
    #[Groups(['file_person'])]
    private $accessPersons;

    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['file', 'booking_event_files', 'booking_event_documents_files'])]
    private $config;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string')]
    #[Assert\Type(type: 'string')]
    #[Assert\NotNull]
    #[Assert\Choice(callback: ['\AppBundle\Enum\Core\FileFolderEnum', 'toArray'])]
    #[Groups(['file', 'booking_event_files', 'booking_event_documents_files'])]
    private $folder;
    /**
     * @var ArrayCollection<Event>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Booking\Event', mappedBy: 'image')]
    #[Groups(['file_event'])]
    private $events;
    /**
     * @var ArrayCollection<Network>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Network\Network', mappedBy: 'image')]
    #[Groups(['file_network'])]
    private $networks;
    /**
     * @var ArrayCollection<Activity>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Organization\Activity', mappedBy: 'logo')]
    #[Groups(['file_activity'])]
    private $activityLogos;
    /**
     * @var ArrayCollection<Activity>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Organization\Activity', mappedBy: 'imageActivity')]
    #[Groups(['file_activity'])]
    private $activityImages;
    /**
     * @var ArrayCollection<Organization>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Organization\Organization', mappedBy: 'logo')]
    #[Groups(['file_organization'])]
    private $organizationLogos;
    /**
     * @var ArrayCollection<Organization>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Organization\Organization', mappedBy: 'image')]
    #[Groups(['file_organization'])]
    private $organizationImages;
    /**
     * @var ArrayCollection<Person>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Person\Person', mappedBy: 'image')]
    #[Groups(['file_person'])]
    private $personImages;
    /**
     * @var Parameters
     */
    #[ORM\OneToOne(targetEntity: 'AppBundle\Entity\Organization\Parameters', mappedBy: 'qrCode', fetch: 'EAGER')]
    #[Groups(['file'])]
    private $qrCode;
    /**
     * @var EventReport
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Booking\EventReport', inversedBy: 'files')]
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
    #[Groups(['file'])]
    private $eventReport;
    /**
     * @var DocumentWish
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessWish\DocumentWish', inversedBy: 'files', cascade: ['persist'])]
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
    #[Groups(['file'])]
    private $documentWish;
    /**
     * @var DocumentWish
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\OnlineRegistrationSettings', inversedBy: 'introductionFiles', cascade: ['persist'])]
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
    #[Groups(['file'])]
    private $onlineRegistrationSetting;
    /**
     * @var DocumentWish
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\OnlineRegistrationSettings', inversedBy: 'introductionFilesNewEnrolments', cascade: ['persist'])]
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
    #[Groups(['file'])]
    private $onlineRegistrationSettingNewEnrolments;
    /**
     * @var DocumentWish
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Booking\Work', inversedBy: 'files', cascade: ['persist'])]
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
    #[Groups(['file'])]
    private $work;
    /**
     * @var CalendarSynchro
     */
    #[ORM\OneToOne(targetEntity: 'AppBundle\Entity\Booking\CalendarSynchro', mappedBy: 'file', fetch: 'EAGER')]
    #[Groups(['file'])]
    private $calendarSynchro;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', options: ['default' => 'NONE'])]
    #[Assert\Type(type: 'string')]
    #[Assert\NotNull]
    #[Assert\Choice(callback: ['\AppBundle\Enum\Core\FileTypeEnum', 'toArray'])]
    #[Groups(['file', 'booking_event_files', 'access_files_person'])]
    private $type = "NONE";
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'date', nullable: true)]
    #[Assert\Date]
    #[Groups(['file', 'access_files_person'])]
    private $availabilityDate;
    /**
     * @var integer
     */
    #[ORM\Column(type: 'integer', nullable: true)]
    #[Groups(['file'])]
    private $size;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => 0])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['file'])]
    private $isTemporaryFile = false;
    /**
     * @var TemplateSystem
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Message\TemplateSystem', inversedBy: 'files', cascade: ['persist'])]
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
    #[Groups(['file'])]
    private $templateSystem;
    public function __construct()
    {
        $this->accessPersons = new ArrayCollection();
        $this->events = new ArrayCollection();
        $this->networks = new ArrayCollection();
        $this->activityLogos = new ArrayCollection();
        $this->organizationLogos = new ArrayCollection();
        $this->organizationImages = new ArrayCollection();
        $this->personImages = 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;
    }
    /**
     * Gets slug.
     *
     * @return string
     */
    public function getSlug() {
        return $this->slug;
    }
    /**
     * Sets slug.
     *
     * @param string $slug
     * @return $this
     */
    public function setSlug($slug) {
        $this->slug = $slug;
        return $this;
    }
    /**
     * Sets path.
     *
     * @param string $path
     *
     * @return $this
     */
    public function setPath($path)
    {
        $this->path = $path;

        return $this;
    }
    /**
     * Gets path.
     *
     * @return string
     */
    public function getPath()
    {
        return $this->path;
    }
    /**
     * Sets name.
     *
     * @param string $name
     *
     * @return $this
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }
    /**
     * Gets name.
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
    /**
     * Sets mimeType.
     *
     * @param string $mimeType
     *
     * @return $this
     */
    public function setMimeType($mimeType)
    {
        $this->mimeType = $mimeType;

        return $this;
    }
    /**
     * Gets mimeType.
     *
     * @return string
     */
    public function getMimeType()
    {
        return $this->mimeType;
    }
    /**
     * @return Person
     */
    public function getPerson()
    {
        return $this->person;
    }
    /**
     * @param Person $person
     * @return $this
     */
    public function setPerson($person)
    {
        $this->person = $person;
        return $this;
    }
    /**
     * @return Organization
     */
    public function getOrganization()
    {
        return $this->organization;
    }
    /**
     * @param Organization $organization
     * @return $this
     */
    public function setOrganization($organization)
    {
        $this->organization = $organization;
        return $this;
    }
    /**
     * Adds person can access the file.
     *
     * @param Person $person
     *
     * @return $this
     */
    public function addAccessPerson(Person $person)
    {
        $this->accessPersons->add($person);

        return $this;
    }
    /**
     * Removes person has access the file.
     *
     * @param Person $person
     *
     * @return $this
     */
    public function removeAccessPerson(Person $person)
    {

        $this->accessPersons->removeElement($person);
        return $this;
    }
    /**
     * Gets accessPersons.
     *
     * @return ArrayCollection<Person>
     */
    public function getAccessPersons()
    {
        return $this->accessPersons;
    }
    /**
     * @return string
     */
    public function getVisibility()
    {
        return $this->visibility;
    }
    /**
     * @param string $visibility
     * @return $this
     */
    public function setVisibility($visibility)
    {
        $this->visibility = $visibility;
        return $this;
    }
    /**
     * @return array
     */
    public function getAccessRoles()
    {
        return $this->accessRoles;
    }
    /**
     * @param array $accessRoles
     * @return $this
     */
    public function setAccessRoles($accessRoles)
    {
        $this->accessRoles = $accessRoles;
        return $this;
    }
    /**
     * @return mixed
     */
    public function getConfig()
    {
        return $this->config;
    }
    /**
     * @param mixed $config
     * @return $this
     */
    public function setConfig($config)
    {
        $this->config = $config;
        return $this;
    }
    /**
     * Set folder
     *
     * @param string $folder
     *
     * @return $this
     */
    public function setFolder($folder)
    {
        $this->folder = $folder;

        return $this;
    }
    /**
     * Get folder
     *
     * @return string
     */
    public function getFolder()
    {
        return $this->folder;
    }
    #[Assert\Callback]
    public function validatePersonOrOrganization(ExecutionContextInterface $context)
    {
        if ((empty($this->person) && empty($this->organization))) {
            $context->buildViolation('You must specify one Person or one Organization')->atPath('person')->addViolation();
            $context->buildViolation('You must specify one Person or one Organization')->atPath('organization')->addViolation();
        }
    }
    /**
     * Add event
     *
     * @param \AppBundle\Entity\Booking\Event $event
     *
     * @return File
     */
    public function addEvent(\AppBundle\Entity\Booking\Event $event)
    {
        $this->events[] = $event;

        return $this;
    }
    /**
     * Remove event
     *
     * @param \AppBundle\Entity\Booking\Event $event
     */
    public function removeEvent(\AppBundle\Entity\Booking\Event $event)
    {
        $this->events->removeElement($event);
    }
    /**
     * Get events
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getEvents()
    {
        return $this->events;
    }
    /**
     * Add network
     *
     * @param \AppBundle\Entity\Network\Network $network
     *
     * @return File
     */
    public function addNetwork(\AppBundle\Entity\Network\Network $network)
    {
        $this->networks[] = $network;

        return $this;
    }
    /**
     * Remove network
     *
     * @param \AppBundle\Entity\Network\Network $network
     */
    public function removeNetwork(\AppBundle\Entity\Network\Network $network)
    {
        $this->networks->removeElement($network);
    }
    /**
     * Get networks
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getNetworks()
    {
        return $this->networks;
    }
    /**
     * Add activityLogo
     *
     * @param \AppBundle\Entity\Organization\Activity $activityLogo
     *
     * @return File
     */
    public function addActivityLogo(\AppBundle\Entity\Organization\Activity $activityLogo)
    {
        $this->activityLogos[] = $activityLogo;

        return $this;
    }
    /**
     * Remove activityLogo
     *
     * @param \AppBundle\Entity\Organization\Activity $activityLogo
     */
    public function removeActivityLogo(\AppBundle\Entity\Organization\Activity $activityLogo)
    {
        $this->activityLogos->removeElement($activityLogo);
    }
    /**
     * Get activityLogos
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getActivityLogos()
    {
        return $this->activityLogos;
    }
    /**
     * Add activityImage
     *
     * @param \AppBundle\Entity\Organization\Activity $activityImage
     *
     * @return File
     */
    public function addActivityImage(\AppBundle\Entity\Organization\Activity $activityImage)
    {
        $this->activityImages[] = $activityImage;

        return $this;
    }
    /**
     * Remove activityImage
     *
     * @param \AppBundle\Entity\Organization\Activity $activityImage
     */
    public function removeActivityImage(\AppBundle\Entity\Organization\Activity $activityImage)
    {
        $this->activityImages->removeElement($activityImage);
    }
    /**
     * Get activityImages
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getActivityImages()
    {
        return $this->activityImages;
    }
    /**
     * Add organizationLogo
     *
     * @param \AppBundle\Entity\Organization\Organization $organizationLogo
     *
     * @return File
     */
    public function addOrganizationLogo(\AppBundle\Entity\Organization\Organization $organizationLogo)
    {
        $this->organizationLogos[] = $organizationLogo;

        return $this;
    }
    /**
     * Remove organizationLogo
     *
     * @param \AppBundle\Entity\Organization\Organization $organizationLogo
     */
    public function removeOrganizationLogo(\AppBundle\Entity\Organization\Organization $organizationLogo)
    {
        $this->organizationLogos->removeElement($organizationLogo);
    }
    /**
     * Get organizationLogos
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOrganizationLogos()
    {
        return $this->organizationLogos;
    }
    /**
     * Add organizationImage
     *
     * @param \AppBundle\Entity\Organization\Organization $organizationImage
     *
     * @return File
     */
    public function addOrganizationImage(\AppBundle\Entity\Organization\Organization $organizationImage)
    {
        $this->organizationImages[] = $organizationImage;

        return $this;
    }
    /**
     * Remove organizationImage
     *
     * @param \AppBundle\Entity\Organization\Organization $organizationImage
     */
    public function removeOrganizationImage(\AppBundle\Entity\Organization\Organization $organizationImage)
    {
        $this->organizationImages->removeElement($organizationImage);
    }
    /**
     * Get organizationImages
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOrganizationImages()
    {
        return $this->organizationImages;
    }
    /**
     * Add personImage
     *
     * @param \AppBundle\Entity\Person\Person $personImage
     *
     * @return File
     */
    public function addPersonImage(\AppBundle\Entity\Person\Person $personImage)
    {
        $this->personImages[] = $personImage;

        return $this;
    }
    /**
     * Remove personImage
     *
     * @param \AppBundle\Entity\Person\Person $personImage
     */
    public function removePersonImage(\AppBundle\Entity\Person\Person $personImage)
    {
        $this->personImages->removeElement($personImage);
    }
    /**
     * Get personImages
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getPersonImages()
    {
        return $this->personImages;
    }
    /**
     * Set qrCode
     *
     * @param $qrCode
     *
     * @return File
     */
    public function setQrCode($qrCode)
    {
        $this->qrCode = $qrCode;
        return $this;
    }
    /**
     * Get qrCode
     *
     * @return string
     */
    public function getQrCode()
    {
        return $this->qrCode;
    }
    /**
     * Set type
     *
     * @param string $type
     *
     * @return File
     */
    public function setType($type)
    {
        $this->type = $type;

        return $this;
    }
    /**
     * Get type
     *
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }
    /**
     * @return EventReport
     */
    public function getEventReport()
    {
        return $this->eventReport;
    }
    /**
     * @param EventReport $eventReport
     * @return $this
     */
    public function setEventReport($eventReport)
    {
        $this->eventReport = $eventReport;
        return $this;
    }
    /**
     * Set availabilityDate
     *
     * @param \DateTime $availabilityDate
     *
     * @return File
     */
    public function setAvailabilityDate($availabilityDate)
    {
        $this->availabilityDate = $availabilityDate;

        return $this;
    }
    /**
     * Get availabilityDate
     *
     * @return \DateTime
     */
    public function getAvailabilityDate()
    {
        return $this->availabilityDate;
    }
    /**
     * Set documentWish
     *
     * @param \AppBundle\Entity\AccessWish\DocumentWish $documentWish
     *
     * @return File
     */
    public function setDocumentWish(\AppBundle\Entity\AccessWish\DocumentWish $documentWish = null)
    {
        $this->documentWish = $documentWish;

        return $this;
    }
    /**
     * Get documentWish
     *
     * @return \AppBundle\Entity\AccessWish\DocumentWish
     */
    public function getDocumentWish()
    {
        return $this->documentWish;
    }
    /**
     * Set size
     *
     * @param integer $size
     *
     * @return File
     */
    public function setSize($size)
    {
        $this->size = $size;

        return $this;
    }
    /**
     * Get size
     *
     * @return integer
     */
    public function getSize()
    {
        return $this->size;
    }
    /**
     * @return bool
     */
    public function isTemporaryFile()
    {
        return $this->isTemporaryFile;
    }
    /**
     * @param bool $isTemporaryFile
     */
    public function setIsTemporaryFile($isTemporaryFile)
    {
        $this->isTemporaryFile = $isTemporaryFile;

        return $this;
    }
    /**
     * Set calendarSynchro
     *
     * @param \AppBundle\Entity\Booking\CalendarSynchro $calendarSynchro
     *
     * @return File
     */
    public function setCalendarSynchro(\AppBundle\Entity\Booking\CalendarSynchro $calendarSynchro = null)
    {
        $this->calendarSynchro = $calendarSynchro;

        return $this;
    }
    /**
     * Get calendarSynchro
     *
     * @return \AppBundle\Entity\Booking\CalendarSynchro
     */
    public function getCalendarSynchro()
    {
        return $this->calendarSynchro;
    }
    /**
     * Get isTemporaryFile
     *
     * @return boolean
     */
    public function getIsTemporaryFile()
    {
        return $this->isTemporaryFile;
    }
    /**
     * Set onlineRegistrationSetting
     *
     * @param \AppBundle\Entity\Organization\OnlineRegistrationSettings $onlineRegistrationSetting
     *
     * @return File
     */
    public function setOnlineRegistrationSetting(\AppBundle\Entity\Organization\OnlineRegistrationSettings $onlineRegistrationSetting = null)
    {
        $this->onlineRegistrationSetting = $onlineRegistrationSetting;

        return $this;
    }
    /**
     * Get onlineRegistrationSetting
     *
     * @return \AppBundle\Entity\Organization\OnlineRegistrationSettings
     */
    public function getOnlineRegistrationSetting()
    {
        return $this->onlineRegistrationSetting;
    }
    /**
     * Set templateSystem
     *
     * @param TemplateSystem $templateSystem
     *
     * @return File
     */
    public function setTemplateSystem(TemplateSystem $templateSystem = null)
    {
        $this->templateSystem = $templateSystem;

        return $this;
    }
    /**
     * Get templateSystem
     *
     * @return TemplateSystem
     */
    public function getTemplateSystem()
    {
        return $this->templateSystem;
    }
    /**
     * Set work
     *
     * @param \AppBundle\Entity\Booking\Work $work
     *
     * @return File
     */
    public function setWork(\AppBundle\Entity\Booking\Work $work = null)
    {
        $this->work = $work;

        return $this;
    }
    /**
     * Get work
     *
     * @return \AppBundle\Entity\Booking\Work
     */
    public function getWork()
    {
        return $this->work;
    }
    /**
     * Set onlineRegistrationSettingNewEnrolments
     *
     * @param \AppBundle\Entity\Organization\OnlineRegistrationSettings $onlineRegistrationSettingNewEnrolments
     *
     * @return File
     */
    public function setOnlineRegistrationSettingNewEnrolments(\AppBundle\Entity\Organization\OnlineRegistrationSettings $onlineRegistrationSettingNewEnrolments = null)
    {
        $this->onlineRegistrationSettingNewEnrolments = $onlineRegistrationSettingNewEnrolments;

        return $this;
    }
    /**
     * Get onlineRegistrationSettingNewEnrolments
     *
     * @return \AppBundle\Entity\Organization\OnlineRegistrationSettings
     */
    public function getOnlineRegistrationSettingNewEnrolments()
    {
        return $this->onlineRegistrationSettingNewEnrolments;
    }
}
