<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, unique: true)]
private ?string $username = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $email = null;
#[ORM\Column(length: 255)]
private ?string $password = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?Role $role = null;
// === NUEVOS BOOLEANOS ===
#[ORM\Column(type: 'boolean', options: ['default' => false])]
private bool $crearProyecto = false;
#[ORM\Column(type: 'boolean', options: ['default' => false])]
private bool $mailNotificaciones = false;
// ============================================================
// 🔹 Métodos base
// ============================================================
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): static
{
$this->username = $username;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
public function getRole(): ?Role
{
return $this->role;
}
public function setRole(?Role $role): static
{
$this->role = $role;
return $this;
}
public function getCrearProyecto(): bool
{
return $this->crearProyecto;
}
public function setCrearProyecto(bool $crearProyecto): static
{
$this->crearProyecto = $crearProyecto;
return $this;
}
public function getMailNotificaciones(): bool
{
return $this->mailNotificaciones;
}
public function setMailNotificaciones(bool $mailNotificaciones): static
{
$this->mailNotificaciones = $mailNotificaciones;
return $this;
}
// ============================================================
// 🔒 Métodos requeridos por UserInterface
// ============================================================
public function __toString(): string
{
return $this->username ?? ''; // o usa otro campo, como $this->email o $this->nombreCompleto
}
public function getUserIdentifier(): string
{
return (string) $this->username;
}
public function getRoles(): array
{
return [$this->role ? $this->role->getName() : 'ROLE_USER'];
}
public function eraseCredentials(): void {}
public function getSalt(): ?string
{
return null;
}
}