<?php
namespace App\Entity\User;
use App\Repository\User\IdentityRepository;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=IdentityRepository::class)
*/
class Identity
{
const GENDER_MALE = 'M';
const GENDER_FEMALE = 'MME';
const GENDER_LIST = [
self::GENDER_MALE,
self::GENDER_FEMALE,
];
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @SerializedName("id")
* @Assert\Uuid()
* @Groups({
* "User:output",
* "get_godfather_by_godchild_email",
* "SponsorshipRequest:io",
* })
*/
private string $id;
/**
* @ORM\Column(type="string", length=25)
* @SerializedName("first_name")
* @Assert\Length(max="25")
* @Groups({"User:io", "get_godfather_by_godchild_email", "SponsorshipRequest:io"})
* @Assert\Regex("/^[a-zA-Z-ëêéèâàäôïîç ]*$/",
* message = "Numbers or special characters are not allowed")
*/
private string $firstName;
/**
* @ORM\Column(type="string", length=25)
* @SerializedName("last_name")
* @Assert\Length(max="25")
* @Groups({"User:io", "get_godfather_by_godchild_email", "SponsorshipRequest:io"})
* @Assert\Regex("/^[a-zA-Z-ëêéèâàäôïîç ]*$/",
* message = "Numbers or special characters are not allowed")
*/
private string $lastName;
/**
* @ORM\Column(type="string", length=5, columnDefinition="ENUM('M', 'MME')")
* @SerializedName("gender")
* @Assert\Length(max="5")
* @Assert\Choice(choices=Identity::GENDER_LIST)
* @Groups({"User:io"})
*/
private ?string $gender = null;
/**
* @ORM\Column(type="datetime", nullable=true)
* @SerializedName("birthdate")
* @Assert\GreaterThan("1900-01-01")
* @Groups({"User:io"})
*/
private ?DateTime $birthdate = null;
/**
* @ORM\OneToOne(targetEntity=Identity::class)
* @ORM\JoinColumn(name="previous_identity_id", referencedColumnName="id", nullable=true)
* @Groups({"User:io"})
*/
private ?Identity $previousIdentity;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->previousIdentity = null;
}
/**
* @return string
*/
public function getId(): ?string
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(string $gender): self
{
$this->gender = $gender;
return $this;
}
public function getFormatedGender(): string
{
return ucfirst(strtolower($this->gender));
}
public function getBirthdate(): ?DateTime
{
return $this->birthdate;
}
public function setBirthdate(?DateTime $birthdate): Identity
{
$this->birthdate = $birthdate;
return $this;
}
public function __toString(): string
{
return $this->firstName;
}
public function getPreviousIdentity() : ?Identity
{
return $this->previousIdentity;
}
public function setPreviousIdentity(?Identity $previousIdentity) : ?Identity
{
$this->previousIdentity = $previousIdentity;
return $this;
}
}