<?php
namespace App\Entity;
use App\Entity\Traits\TimeStampable;
use App\Repository\BailleurRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: BailleurRepository::class)]
#[UniqueEntity(
fields: ['email',],
errorPath: 'email',
message: 'Adresse e-mail déjà utilisée',
)]
#[UniqueEntity(
fields: ['name',],
errorPath: 'name',
message: 'Le nom que vous avez saisi est déjà utilisé',
)]
#[ORM\HasLifecycleCallbacks]
class Bailleur
{
use TimeStampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(["projetBailleur:read", "entity:write", "activiteBailleur:read",'activity:read'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(["projetBailleur:read", "entity:write", "activiteBailleur:read", 'activity:read'])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $name = null;
#[ORM\Column(length: 255)]
#[Groups(["projetBailleur:read", "entity:write", "activiteBailleur:read", 'activity:read'])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $sigle = null;
#[ORM\Column(length: 255)]
#[Groups(["projetBailleur:read", "entity:write", "activiteBailleur:read", 'activity:read'])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $siege = null;
#[ORM\OneToMany(mappedBy: 'bailleur', targetEntity: ProjetBailleur::class)]
private Collection $projetBailleurs;
#[ORM\Column(length: 255)]
#[Groups(["entity:write"])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $phone = null;
#[ORM\Column(length: 255)]
#[Groups(["entity:write"])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
#[Assert\Email(message: "Veuillez entrez un email correcte")]
private ?string $email = null;
#[ORM\ManyToOne(inversedBy: 'bailleurs')]
private ?User $createdBy = null;
#[ORM\OneToMany(mappedBy: 'bailleur', targetEntity: ActiviteBailleur::class)]
private Collection $activiteBailleurs;
public function __construct()
{
$this->projetBailleurs = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$this->activiteBailleurs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSigle(): ?string
{
return $this->sigle;
}
public function setSigle(string $sigle): self
{
$this->sigle = $sigle;
return $this;
}
public function getSiege(): ?string
{
return $this->siege;
}
public function setSiege(string $siege): self
{
$this->siege = $siege;
return $this;
}
/**
* @return Collection<int, ProjetBailleur>
*/
public function getProjetBailleurs(): Collection
{
return $this->projetBailleurs;
}
public function addProjetBailleur(ProjetBailleur $projetBailleur): self
{
if (!$this->projetBailleurs->contains($projetBailleur)) {
$this->projetBailleurs->add($projetBailleur);
$projetBailleur->setBailleur($this);
}
return $this;
}
public function removeProjetBailleur(ProjetBailleur $projetBailleur): self
{
if ($this->projetBailleurs->removeElement($projetBailleur)) {
// set the owning side to null (unless already changed)
if ($projetBailleur->getBailleur() === $this) {
$projetBailleur->setBailleur(null);
}
}
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): static
{
$this->createdBy = $createdBy;
return $this;
}
/**
* @return Collection<int, ActiviteBailleur>
*/
public function getActiviteBailleurs(): Collection
{
return $this->activiteBailleurs;
}
public function addActiviteBailleur(ActiviteBailleur $activiteBailleur): static
{
if (!$this->activiteBailleurs->contains($activiteBailleur)) {
$this->activiteBailleurs->add($activiteBailleur);
$activiteBailleur->setBailleur($this);
}
return $this;
}
public function removeActiviteBailleur(ActiviteBailleur $activiteBailleur): static
{
if ($this->activiteBailleurs->removeElement($activiteBailleur)) {
// set the owning side to null (unless already changed)
if ($activiteBailleur->getBailleur() === $this) {
$activiteBailleur->setBailleur(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->name;
}
}