<?php

namespace App\Entity;

use App\Repository\WidgetFormRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Criteria;

/**
 * @ORM\Entity(repositoryClass=WidgetFormRepository::class)
 */
class WidgetForm
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

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

    /**
     * @ORM\OneToMany(targetEntity=WidgetFormInput::class, mappedBy="widgetForm")
     */
    private $widgetFormInputs;

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

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

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    /**
     * @return Collection|WidgetFormInput[]
     */
    public function getWidgetFormInputs(): Collection
    {
        $expr = Criteria::expr();
        $criteria = Criteria::create();
        $criteria->orderBy(['sort' => Criteria::ASC]);
       
        return $this->widgetFormInputs->matching($criteria);
    }

    public function addWidgetFormInput(WidgetFormInput $widgetFormInput): self
    {
        if (!$this->widgetFormInputs->contains($widgetFormInput)) {
            $this->widgetFormInputs[] = $widgetFormInput;
            $widgetFormInput->setWidgetForm($this);
        }

        return $this;
    }

    public function removeWidgetFormInput(WidgetFormInput $widgetFormInput): self
    {
        if ($this->widgetFormInputs->removeElement($widgetFormInput)) {
            // set the owning side to null (unless already changed)
            if ($widgetFormInput->getWidgetForm() === $this) {
                $widgetFormInput->setWidgetForm(null);
            }
        }

        return $this;
    }
}
