<?php

namespace App\Entity;

use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;

#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

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

    /**
     * @var list<string> The user roles
     */
    #[ORM\Column]
    private array $roles = [];

    /**
     * @var string The hashed password
     */
    #[ORM\Column]
    private ?string $password = null;

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

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

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

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

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

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

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

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

    #[ORM\Column]
    private bool $isVerified = false;

    public function __construct()
    {
        $this->quiParticipes = new ArrayCollection();
        $this->quiOrganises = new ArrayCollection();
        $this->paniers = new ArrayCollection();
        $this->parrainages = new ArrayCollection();
    }

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

    public function getEmail(): ?string
    {
        return $this->email;
    }

    public function setEmail(string $email): static
    {
        $this->email = $email;

        return $this;
    }

    /**
     * A visual identifier that represents this user.
     *
     * @see UserInterface
     */
    public function getUserIdentifier(): string
    {
        return (string) $this->email;
    }

    /**
     * @see UserInterface
     *
     * @return list<string>
     */
    public function getRoles(): array
    {
        $roles = $this->roles;
        // guarantee every user at least has ROLE_USER
        $roles[] = 'ROLE_USER';

        return array_unique($roles);
    }

    /**
     * @param list<string> $roles
     */
    public function setRoles(array $roles): static
    {
        $this->roles = $roles;

        return $this;
    }

    /**
     * @see PasswordAuthenticatedUserInterface
     */
    public function getPassword(): ?string
    {
        return $this->password;
    }

    public function setPassword(string $password): static
    {
        $this->password = $password;

        return $this;
    }

    /**
     * @see UserInterface
     */
    public function eraseCredentials(): void
    {
        // If you store any temporary, sensitive data on the user, clear it here
        // $this->plainPassword = null;
    }

    public function getNom(): ?string
    {
        return $this->nom;
    }

    public function setNom(string $nom): static
    {
        $this->nom = $nom;

        return $this;
    }

    public function getPrenom(): ?string
    {
        return $this->prenom;
    }

    public function setPrenom(string $prenom): static
    {
        $this->prenom = $prenom;

        return $this;
    }

    public function getAdresse(): ?string
    {
        return $this->adresse;
    }

    public function setAdresse(string $adresse): static
    {
        $this->adresse = $adresse;

        return $this;
    }

    public function getTelephone(): ?string
    {
        return $this->telephone;
    }

    public function setTelephone(string $telephone): static
    {
        $this->telephone = $telephone;

        return $this;
    }

    /**
     * @return Collection<int, QuiParticipe>
     */
    public function getQuiParticipes(): Collection
    {
        return $this->quiParticipes;
    }

    public function addQuiParticipe(QuiParticipe $quiParticipe): static
    {
        if (!$this->quiParticipes->contains($quiParticipe)) {
            $this->quiParticipes->add($quiParticipe);
            $quiParticipe->setUser($this);
        }

        return $this;
    }

    public function removeQuiParticipe(QuiParticipe $quiParticipe): static
    {
        if ($this->quiParticipes->removeElement($quiParticipe)) {
            // set the owning side to null (unless already changed)
            if ($quiParticipe->getUser() === $this) {
                $quiParticipe->setUser(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, QuiOrganise>
     */
    public function getQuiOrganises(): Collection
    {
        return $this->quiOrganises;
    }

    public function addQuiOrganise(QuiOrganise $quiOrganise): static
    {
        if (!$this->quiOrganises->contains($quiOrganise)) {
            $this->quiOrganises->add($quiOrganise);
            $quiOrganise->setUser($this);
        }

        return $this;
    }

    public function removeQuiOrganise(QuiOrganise $quiOrganise): static
    {
        if ($this->quiOrganises->removeElement($quiOrganise)) {
            // set the owning side to null (unless already changed)
            if ($quiOrganise->getUser() === $this) {
                $quiOrganise->setUser(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Panier>
     */
    public function getPaniers(): Collection
    {
        return $this->paniers;
    }

    public function addPanier(Panier $panier): static
    {
        if (!$this->paniers->contains($panier)) {
            $this->paniers->add($panier);
            $panier->setUser($this);
        }

        return $this;
    }

    public function removePanier(Panier $panier): static
    {
        if ($this->paniers->removeElement($panier)) {
            // set the owning side to null (unless already changed)
            if ($panier->getUser() === $this) {
                $panier->setUser(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Parrainage>
     */
    public function getParrainages(): Collection
    {
        return $this->parrainages;
    }

    public function addParrainage(Parrainage $parrainage): static
    {
        if (!$this->parrainages->contains($parrainage)) {
            $this->parrainages->add($parrainage);
            $parrainage->setUser($this);
        }

        return $this;
    }

    public function removeParrainage(Parrainage $parrainage): static
    {
        if ($this->parrainages->removeElement($parrainage)) {
            // set the owning side to null (unless already changed)
            if ($parrainage->getUser() === $this) {
                $parrainage->setUser(null);
            }
        }

        return $this;
    }

    public function isVerified(): bool
    {
        return $this->isVerified;
    }

    public function setIsVerified(bool $isVerified): static
    {
        $this->isVerified = $isVerified;

        return $this;
    }
}
