<?php

namespace AppBundle\Entity\Message;

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


/**
 * Template system
 */
#[ORM\Entity(repositoryClass: 'AppBundle\Entity\Message\Repository\TemplateSystemRepository')]
#[ORM\Table(name: 'TemplateSystem')]
#[ORM\UniqueConstraint(name: 'template_organization_idx', columns: ['template', 'organization_id'])]
class TemplateSystem
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['templatesystem'])]
    private $id;
    /**
     * @var Organization
     *
     * @DefaultField
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\Organization')]
    #[Groups(['templatesystem'])]
    private $organization;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['templatesystem'])]
    private $subject;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string')]
    #[Assert\Type(type: 'string')]
    #[Assert\Choice(callback: ['AppBundle\Enum\Message\TemplateSystemEnum', 'toArray'])]
    #[Groups(['templatesystem'])]
    private $template;
    /**
     * @var string
     */
    #[ORM\Column(type: 'text', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['templatesystem'])]
    private $text;
    /**
     * @var ArrayCollection<File>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Core\File', mappedBy: 'templateSystem', orphanRemoval: true)]
    #[Groups(['templatesystem'])]
    private $files;
    public function __construct()
    {
        $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;
    }
    /**
     * Set organization
     *
     * @param Organization $organization
     *
     * @return TemplateSystem
     */
    public function setOrganization(Organization $organization = null)
    {
        $this->organization = $organization;

        return $this;
    }
    /**
     * Get organization
     *
     * @return Organization
     */
    public function getOrganization()
    {
        return $this->organization;
    }
    /**
     * Sets subject.
     *
     * @param string $subject
     *
     * @return $this
     */
    public function setSubject($subject)
    {
        $this->subject = $subject;

        return $this;
    }
    /**
     * Gets subject.
     *
     * @return string
     */
    public function getSubject()
    {
        return $this->subject;
    }
    /**
     * Sets template.
     *
     * @param string $template
     *
     * @return $this
     */
    public function setTemplate($template)
    {
        $this->template = $template;

        return $this;
    }
    /**
     * Gets template.
     *
     * @return string
     */
    public function getTemplate()
    {
        return $this->template;
    }
    /**
     * Set text
     *
     * @param string $text
     *
     * @return Message
     */
    public function setText($text)
    {
        $this->text = $text;

        return $this;
    }
    /**
     * Get text
     *
     * @return string
     */
    public function getText()
    {
        return html_entity_decode($this->text);
    }
    /**
     * Adds file.
     *
     * @param File $file
     *
     * @return $this
     */
    public function addFile(File $file)
    {
        $file->setTemplateSystem($this);
        $this->files->add($file);

        return $this;
    }
    /**
     * Removes file.
     *
     * @param File $file
     *
     * @return $this
     */
    public function removeFile(File $file)
    {

        $this->files->removeElement($file);
        return $this;
    }
    /**
     * Gets files.
     *
     * @return ArrayCollection<File>
     */
    public function getFiles()
    {
        return $this->files;
    }
}
