<?php
/**
 * FormField
 *
 * @author Elze Kool <info@visualmedia.nl>
 */

namespace VisualM\FormBundle\Entity;

use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use VisualM\FormBundle\Model\FormFieldModel;
use VisualM\AttributenBundle\Model\VertalingsTrait;
use VisualM\AttributenBundle\EventListener\Mapping\Annotation as Attr;


/**
 * FormField
 *
 * @ORM\Entity(repositoryClass="FormFieldRepository")
 * @ORM\Table(name="form_field", indexes= {
 *    @ORM\Index(name="form_fields_idx", columns={ "form_id", "volgorde" })
 * })
 * @UniqueEntity(fields = { "form", "referentie" }, message = "form_field.referentie.unique", errorPath = "referentie")
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
class FormField extends FormFieldModel implements FormFieldInterface
{
    use VertalingsTrait;

    const HIDDEN = 'hidden';
    const TEXT = 'text';
    const NUMBER = 'number';
    const INTEGER = 'integer';
    const PHONE = 'phone';
    const EMAIL = 'email';
    const DATE = 'date';
    const TEXTAREA = 'textarea';
    const SELECT = 'select';
    const SELECTLIST = 'selectlist';
    const CHECKBOXLIST = 'checkboxlist';
    const OPTIONLIST = 'optionlist';
    const FILE = "file";
    const GOOGLE_RECAPTCHA_V3 = "google_recaptcha";

    /**
     * @var int
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var Form
     * @ORM\ManyToOne(targetEntity="Form", inversedBy="fields")
     * @ORM\JoinColumn(name="form_id", referencedColumnName="id", nullable = false)
     */
    private $form;

    /**
     * @var int
     * @ORM\Column(name="volgorde", type="integer", nullable = false)
     */
    private $volgorde;

    /**
     * @var string
     * @ORM\Column(name="titel", type="string", nullable = false)
     * @Assert\NotBlank(message = "form_field.titel.not_blank")
      * @Attr\Vertaalbaar
     */
    private $titel;

    /**
     * @var string
     * @ORM\Column(name="referentie", type="string", nullable=false, unique=false)
     * @Assert\NotBlank(message = "form_field.referentie.not_blank")
     * @Assert\Regex(pattern = "/^[a-z0-9_\-]+$/", message = "form_field.referentie.regex")
     */
    private $referentie;

    /**
     * @var string
     * @ORM\Column(name="type", type="string", nullable = false)
     * @Assert\NotBlank(message = "form_field.type.not_blank")
     */
    private $type;

    /**
     * @var bool
     * @ORM\Column(name="verplicht", type="boolean", nullable = false)
     * @Assert\NotNull(message = "form_field.verplicht.not_blank")
     */
    private $verplicht;

    /**
     * @var int
     * @ORM\Column(name="rijen", type="integer", nullable = true)
     */
    private $rijen;

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

    /**
     * @var waarden
     * @ORM\Column(name="waarden", type="text", nullable = true)
     */
    private $waarden;

    /**
     * @var DateTime
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(name="toegevoegd", type="datetime")
     */
    protected $toegevoegd;

    /**
     * @var DateTime
     * @Gedmo\Timestampable(on="update")
     * @ORM\Column(name="gewijzigd", type="datetime")
     */
    protected $gewijzigd;

    /**
     * @ORM\Column(name="label", type="boolean", nullable = false)
     */
    protected $label;

    /**
     * @var string
     * @ORM\Column(name="css_class", type="string", nullable = true)
     */
    protected $css_class;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->type = self::TEXT;
        $this->verplicht = false;
        $this->volgorde = 0;
        $this->rijen = 2;
        $this->label = true;
    }

    /**
     * Get string representation
     *
     * @return string String representation
     */
    public function __toString()
    {
        return $this->titel;
    }

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

    /**
     * Get Form
     *
     * @return Form Form
     **/
    public function getForm()
    {
        return $this->form;
    }

    /**
     * Set Form
     *
     * @param Form $form Form
     **/
    public function setForm($form)
    {
        $this->form = $form;
    }

    /**
     * Get Volgorde
     *
     * @return int Volgorde
     **/
    public function getVolgorde()
    {
        return $this->volgorde;
    }

    /**
     * Set Volgorde
     *
     * @param int $volgorde Volgorde
     **/
    public function setVolgorde($volgorde)
    {
        $this->volgorde = $volgorde;
    }

    /**
     * Get Titel
     *
     * @return string Titel
     **/
    public function getTitel()
    {
        return $this->titel;
    }

    /**
     * Set Titel
     *
     * @param string $titel Titel
     **/
    public function setTitel($titel)
    {
        $this->titel = $titel;
    }

    /**
     * Get Referentie
     *
     * @return string Referentie
     **/
    public function getReferentie()
    {
        return $this->referentie;
    }

    /**
     * Set Referentie
     *
     * @param string $referentie Referentie
     **/
    public function setReferentie($referentie)
    {
        $this->referentie = $referentie;
    }

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

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

    /**
     * Get Verplicht
     *
     * @return bool Verplicht
     **/
    public function getVerplicht()
    {
        return $this->verplicht;
    }

    /**
     * Set Verplicht
     *
     * @param bool $verplicht Verplicht
     **/
    public function setVerplicht($verplicht)
    {
        $this->verplicht = $verplicht;
    }

    /**
     * Get Grootte
     *
     * @return string Grootte
     **/
    public function getGrootte()
    {
        return $this->grootte;
    }

    /**
     * Set Grootte
     *
     * @param string $grootte Grootte
     **/
    public function setGrootte($grootte)
    {
        $this->grootte = $grootte;
    }

    /**
     * Get Rijen
     *
     * @return int Rijen
     **/
    public function getRijen()
    {
        return $this->rijen;
    }

    /**
     * Set Rijen
     *
     * @param int $rijen Rijen
     **/
    public function setRijen($rijen)
    {
        $this->rijen = $rijen;
    }

    /**
     * Get Regex
     *
     * @return string Regex
     **/
    public function getRegex()
    {
        return $this->regex;
    }

    /**
     * Set Regex
     *
     * @param string $regex Regex
     **/
    public function setRegex($regex)
    {
        $this->regex = $regex;
    }

    /**
     * @return string Imploded opties
     *
     * Wordt gebruikt om opties uit te maken, niet als initiele waarde
     **/
    public function getWaarden()
    {
        return $this->waarden;
    }

    /**
     * @param string $waarden Imploded opties
     *
     * Wordt gebruikt om choices uit te maken, niet als initiele waarde
     **/
    public function setWaarden($waarden)
    {
        $this->waarden = $waarden;
    }

    /**
     * Get DateTime
     *
     * @return Toegevoegd DateTime
     **/
    public function getToegevoegd()
    {
        return $this->toegevoegd;
    }

    /**
     * Set DateTime
     *
     * @param Toegevoegd $toegevoegd DateTime
     **/
    public function setToegevoegd($toegevoegd)
    {
        $this->toegevoegd = $toegevoegd;
    }

    /**
     * Get Gewijzigd
     *
     * @return DateTime Gewijzigd
     **/
    public function getGewijzigd()
    {
        return $this->gewijzigd;
    }

    /**
     * Set Gewijzigd
     *
     * @param DateTime $gewijzigd Gewijzigd
     **/
    public function setGewijzigd($gewijzigd)
    {
        $this->gewijzigd = $gewijzigd;
    }


    /**
     * Get lengte wordt nog niet ondersteund
     *
     * @return null
     */
    public function getLengte()
    {
        return null;
    }

    /**
     * Get schaal wordt nog niet opgeslagen
     *
     * @return 2
     */
    public function getSchaal()
    {
        return 2;
    }

    /**
     *  Set label
     *
     *  @param label
     */
    public function setLabel($label){
        $this->label = $label;
    }

    /**
     *  Get label
     *
     *  @return label Booealn
     */
    public function getLabel(){
        return $this->label;
    }

    /**
     *  Set css_class
     *
     *  @param css_class
     */
    public function setCssClass($css_class){
        $this->css_class = $css_class;
    }

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