<?php
namespace App\Entity;
use App\Repository\EmailBlacklistRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: EmailBlacklistRepository::class)]
#[ORM\Table(name: 'email_blacklist')]
#[ORM\Index(name: 'idx_email', columns: ['email'])]
#[UniqueEntity(fields: ['email'], message: 'Cet email est déjà dans la blacklist.')]
class EmailBlacklist
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255, unique: true)]
#[Assert\NotBlank(message: 'L\'email ne peut pas être vide.')]
#[Assert\Email(message: 'L\'email n\'est pas valide.')]
private ?string $email = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $reason = null;
#[ORM\Column(type: 'datetime_immutable')]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private bool $isActive = true;
#[ORM\Column(type: 'string', length: 50, nullable: true)]
private ?string $addedBy = null;
#[ORM\Column(type: 'integer', options: ['default' => 0])]
private int $blockCount = 0;
#[ORM\Column(type: 'string', length: 255)]
private $name;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->isActive = true;
$this->blockCount = 0;
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = strtolower(trim($email));
return $this;
}
public function getReason(): ?string
{
return $this->reason;
}
public function setReason(?string $reason): self
{
$this->reason = $reason;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function isActive(): bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getAddedBy(): ?string
{
return $this->addedBy;
}
public function setAddedBy(?string $addedBy): self
{
$this->addedBy = $addedBy;
return $this;
}
public function getBlockCount(): int
{
return $this->blockCount;
}
public function setBlockCount(int $blockCount): self
{
$this->blockCount = $blockCount;
return $this;
}
public function incrementBlockCount(): self
{
$this->blockCount++;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function __toString(): string
{
return $this->email ?? '';
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
}