<?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 Ramsey\Uuid\Doctrine\UuidGenerator;
use Ramsey\Uuid\UuidInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity('email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\Column(type: "uuid", unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
protected UuidInterface|string $id;
#[ORM\Column(length: 255)]
private ?string $firstName = null;
#[ORM\Column(length: 255)]
private ?string $lastName = null;
#[ORM\Column(length: 255, unique: true)]
private ?string $email = null;
#[ORM\Column(length: 255)]
private ?string $password = null;
#[ORM\Column]
private ?bool $enabled = true;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Location::class, cascade: ['persist'], orphanRemoval: true)]
private Collection $locations;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $phone = null;
#[ORM\Column]
private ?bool $emailVerified = false;
#[ORM\Column(length: 255, nullable: true)]
private ?string $resetPasswordToken;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $resetPasswordRequestAt = null;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Subscription::class)]
private Collection $subscriptions;
#[ORM\Column]
private ?bool $isAdmin = null;
public function __construct()
{
$this->locations = new ArrayCollection();
$this->createdAt = $this->createdAt ?? new \DateTimeImmutable();
$this->subscriptions = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getUserIdentifier()
{
return $this->email;
}
public function getRoles()
{
$roles[] = 'ROLE_USER';
if ($this->isAdmin) {
$roles[] = 'ROLE_ADMIN';
}
return $roles;
}
public function getSalt()
{
// TODO: Implement getSalt() method.
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function getUsername()
{
return $this->email;
}
/**
* @return Collection<int, Location>
*/
public function getLocations(): Collection
{
return $this->locations;
}
public function addLocation(Location $location): self
{
if (!$this->locations->contains($location)) {
$this->locations->add($location);
$location->setUser($this);
}
return $this;
}
public function removeLocation(Location $location): self
{
if ($this->locations->removeElement($location)) {
// set the owning side to null (unless already changed)
if ($location->getUser() === $this) {
$location->setUser(null);
}
}
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getFullName(): ?string
{
return $this->fullName;
}
public function setFullName(?string $fullName): self
{
$this->fullName = $fullName;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getEmailVerified(): ?bool
{
return $this->emailVerified;
}
public function setEmailVerified(?bool $emailVerified): self
{
$this->emailVerified = $emailVerified;
return $this;
}
public function getResetPasswordToken(): ?string
{
return $this->resetPasswordToken;
}
public function setResetPasswordToken(?string $resetPasswordToken): self
{
$this->resetPasswordToken = $resetPasswordToken;
return $this;
}
public function getResetPasswordRequestAt(): ?\DateTimeImmutable
{
return $this->resetPasswordRequestAt;
}
public function setResetPasswordRequestAt(?\DateTimeImmutable $resetPasswordRequestAt): self
{
$this->resetPasswordRequestAt = $resetPasswordRequestAt;
return $this;
}
/**
* @return Collection<int, Subscription>
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): static
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions->add($subscription);
$subscription->setCustomer($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): static
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getCustomer() === $this) {
$subscription->setCustomer(null);
}
}
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): static
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): static
{
$this->lastName = $lastName;
return $this;
}
public function isIsAdmin(): ?bool
{
return $this->isAdmin;
}
public function setIsAdmin(bool $isAdmin): static
{
$this->isAdmin = $isAdmin;
return $this;
}
}