<?php

namespace App\Entity;

use App\Repository\QuestionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: QuestionRepository::class)]
class Question
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    private ?string $title = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $name_en = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $name_fr = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $name_ar = null;

    #[ORM\Column]
    private ?bool $choice = null;

    #[ORM\Column(type: Types::SMALLINT)]
    private ?int $type_modality = null;

    #[ORM\Column]
    private ?float $amount = null;

    #[ORM\Column]
    private ?int $max_participant = null;

    /**
     * @var Collection<int, Modality>
     */
    #[ORM\OneToMany(targetEntity: Modality::class, mappedBy: 'question')]
    private Collection $modalitys;

    /**
     * @var Collection<int, Filter>
     */
    #[ORM\OneToMany(targetEntity: Filter::class, mappedBy: 'question')]
    private Collection $filters;

    #[ORM\ManyToOne(inversedBy: 'questions')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Investigation $investigation = null;


    public function __construct()
    {
        $this->modalitys = new ArrayCollection();
        $this->filters = new ArrayCollection();
        $this->choice = false;
        $this->amount = 0;
        $this->max_participant = 0;
    }

    public function __clone()
    {
        $this->title = $this->title ." duplicate";

        $this->name_en = $this->name_en ." duplicate";
        $this->name_fr = $this->name_fr ." duplicate";
        $this->name_ar = $this->name_ar ." duplicate";

        $this->modalitys = new ArrayCollection();
        $this->filters = new ArrayCollection();
        $this->choice = false;
        $this->amount = 0;
        $this->max_participant = 0;
    }

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

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(string $title): static
    {
        $this->title = $title;

        return $this;
    }

    public function getNameEn(): ?string
    {
        return $this->name_en;
    }

    public function setNameEn(?string $name_en): static
    {
        $this->name_en = $name_en;

        return $this;
    }

    public function getNameFr(): ?string
    {
        return $this->name_fr;
    }

    public function setNameFr(?string $name_fr): static
    {
        $this->name_fr = $name_fr;

        return $this;
    }

    public function getNameAr(): ?string
    {
        return $this->name_ar;
    }

    public function setNameAr(?string $name_ar): static
    {
        $this->name_ar = $name_ar;

        return $this;
    }

    public function isChoice(): ?bool
    {
        return $this->choice;
    }

    public function setChoice(bool $choice): static
    {
        $this->choice = $choice;

        return $this;
    }

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

    public function setTypeModality(int $type_modality): static
    {
        $this->type_modality = $type_modality;

        return $this;
    }

    public function getAmount(): ?float
    {
        return $this->amount;
    }

    public function setAmount(float $amount): static
    {
        $this->amount = $amount;

        return $this;
    }

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

    public function setMaxParticipant(int $max_participant): static
    {
        $this->max_participant = $max_participant;

        return $this;
    }

    /**
     * @return Collection<int, Modality>
     */
    public function getModalitys(): Collection
    {
        return $this->modalitys;
    }

    public function addModality(Modality $modality): static
    {
        if (!$this->modalitys->contains($modality)) {
            $this->modalitys->add($modality);
            $modality->setQuestion($this);
        }

        return $this;
    }

    public function removeModality(Modality $modality): static
    {
        if ($this->modalitys->removeElement($modality)) {
            // set the owning side to null (unless already changed)
            if ($modality->getQuestion() === $this) {
                $modality->setQuestion(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Filter>
     */
    public function getFilters(): Collection
    {
        return $this->filters;
    }

    public function addFilter(Filter $filter): static
    {
        if (!$this->filters->contains($filter)) {
            $this->filters->add($filter);
            $filter->setQuestion($this);
        }

        return $this;
    }

    public function removeFilter(Filter $filter): static
    {
        if ($this->filters->removeElement($filter)) {
            // set the owning side to null (unless already changed)
            if ($filter->getQuestion() === $this) {
                $filter->setQuestion(null);
            }
        }

        return $this;
    }

    public function getInvestigation(): ?Investigation
    {
        return $this->investigation;
    }

    public function setInvestigation(?Investigation $investigation): static
    {
        $this->investigation = $investigation;

        return $this;
    }

    

}
