<?php

namespace App\Entity;

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

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

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

    #[ORM\OneToMany(mappedBy: 'membrefractal', targetEntity: CollectionFractal::class, orphanRemoval: true)]
    private Collection $collectionsFractal;

    #[ORM\OneToMany(mappedBy: 'membreFractal', targetEntity: ClasseurFractal::class)]
    private Collection $classeursFractal;

    #[ORM\OneToOne(mappedBy: 'membreFractal', cascade: ['persist', 'remove'])]
    private ?User $user = null;
    public function __construct()
    {
        $this->collectionsFractal = new ArrayCollection();
        $this->classeursFractal = new ArrayCollection();
    }

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

    public function getClasseursfractal(): Collection
    {
        return $this->classeursFractal;
    }

    public function setClasseursfractal(Collection $classeursfractal): static
    {
        $this->classeursFractal = $classeursfractal;

        return $this;
    }
    public function addClasseursFractal(ClasseurFractal $classeurFractal): static
    {
        if (!$this->classeursFractal->contains($classeurFractal)) {
            $this->classeursFractal->add($classeurFractal);
            $classeurFractal->setMembrefractal($this);
        }
        return $this;
    }
    public function removeClasseursFractal(ClasseurFractal $classeurFractal): static
    {
        if ($this->classeursFractal->removeElement($classeurFractal)) {
            // set the owning side to null (unless already changed)
            if ($classeurFractal->getMembrefractal() === $this) {
                $classeurFractal->setMembrefractal(null);
            }
        }

        return $this;
    }

    public function getPseudo(): ?string
    {
        return $this->pseudo;
    }

    public function setPseudo(string $pseudo): static
    {
        $this->pseudo = $pseudo;

        return $this;
    }

    /**
     * @return Collection<int, CollectionFractal>
     */
    public function getCollectionsFractal(): Collection
    {
        return $this->collectionsFractal;
    }

    public function addCollectionsFractal(CollectionFractal $collectionsFractal): static
    {
        if (!$this->collectionsFractal->contains($collectionsFractal)) {
            $this->collectionsFractal->add($collectionsFractal);
            $collectionsFractal->setMembrefractal($this);
        }

        return $this;
    }

    public function removeCollectionsFractal(CollectionFractal $collectionsFractal): static
    {
        if ($this->collectionsFractal->removeElement($collectionsFractal)) {
            // set the owning side to null (unless already changed)
            if ($collectionsFractal->getMembrefractal() === $this) {
                $collectionsFractal->setMembrefractal(null);
            }
        }

        return $this;
    }
    public function __toString(): string
    {
        return $this->pseudo;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }

    public function setUser(User $user): static
    {
        // set the owning side of the relation if necessary
        if ($user->getMembreFractal() !== $this) {
            $user->setMembreFractal($this);
        }

        $this->user = $user;

        return $this;
    }
}
