<?php
namespace App\Entity;
use App\Repository\ContactRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use App\Enum\ContactStatus;
use App\Enum\Product;
#[ORM\Entity(repositoryClass: ContactRepository::class)]
class Contact
{
private const RGX_NAME = '/^[a-zA-ZÀ-ÖØ-öø-ÿ \'-]+$/u';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(name:"i_id", type: Types::INTEGER, nullable:false, options:["unsigned" => true])]
private ?int $iId = null;
#[ORM\Column(length: 50)]
private Product $eProduct;
#[ORM\Column(length: 30)]
private ContactStatus $eStatus;
#[ORM\Column(length: 255)]
#[Assert\NotBlank]
#[Assert\Email]
private ?string $sEmail = null;
#[ORM\Column(length: 70, nullable: true)]
#[Assert\NotBlank]
#[Assert\Regex(self::RGX_NAME)]
private ?string $sName1 = null;
#[ORM\Column(length: 70)]
#[Assert\NotBlank]
#[Assert\Regex(self::RGX_NAME)]
private ?string $sName2 = null;
#[ORM\Column(length: 20)]
#[Assert\NotBlank]
private ?string $sPhone = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
#[Assert\Type(\DateTimeImmutable::class)]
private \DateTimeImmutable $dtCreation;
#[ORM\Column(length: 20)]
private string $sToken;
#[ORM\Column(length: 255, nullable: true)]
private ?string $sObs = null;
#[ORM\OneToMany(mappedBy: 'contact', targetEntity: Seed::class, cascade: ["persist"])]
private Collection $seeds;
/**
* @var Collection<int, Contact2emails>
*/
#[ORM\OneToMany(mappedBy: 'contact', targetEntity: Contact2emails::class)]
private Collection $contact2emails;
public function __construct(ContactStatus $eStatus, Product $eProduct = null)
{
$this->eStatus = $eStatus;
$this->eProduct = $eProduct ?? Product::none;
$this->sToken = uniqid() . rand(100, 999);
$this->dtCreation = new \DateTimeImmutable();
$this->seeds = new ArrayCollection();
$this->contact2emails = new ArrayCollection();
}
public function getIId(): ?int
{
return $this->iId;
}
public function getEProduct(): Product
{
return $this->eProduct;
}
public function setEProduct(Product $eProduct): static
{
$this->eProduct = $eProduct;
return $this;
}
public function getSStatus(): string
{
return $this->eStatus->value;
}
public function setEStatus(ContactStatus $eStatus): static
{
$this->eStatus = $eStatus;
return $this;
}
public function getSEmail(): ?string
{
return $this->sEmail;
}
public function setSEmail(string $sEmail): static
{
$this->sEmail = strtolower($sEmail);
return $this;
}
public function getSName1(): ?string
{
return $this->sName1;
}
public function setSName1(string $sName1): static
{
$this->sName1 = mb_convert_case(\trim($sName1), MB_CASE_TITLE, 'UTF-8');
return $this;
}
public function getSName2(): ?string
{
return $this->sName2;
}
public function setSName2(string $sName2): static
{
$this->sName2 = mb_convert_case(\trim($sName2), MB_CASE_UPPER_SIMPLE, 'UTF-8');
return $this;
}
public function getSPhone(): ?string
{
return $this->sPhone;
}
public function setSPhone(string $sPhone): static
{
$this->sPhone = $sPhone;
return $this;
}
public function getDtCreation(): \DateTimeImmutable
{
return $this->dtCreation;
}
public function setDtCreation(\DateTimeImmutable $dtCreation): static
{
$this->dtCreation = $dtCreation;
return $this;
}
public function getSToken(): string
{
return $this->sToken;
}
public function setSToken(string $sToken): static
{
$this->sToken = $sToken;
return $this;
}
public function getSObs(): ?string
{
return $this->sObs;
}
public function setSObs(?string $sObs): static
{
$this->sObs = $sObs;
return $this;
}
public function getSeeds(): Collection
{
return $this->seeds;
}
/**
* @return Collection<int, Contact2emails>
*/
public function getContact2emails(): Collection
{
return $this->contact2emails;
}
}