<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\CustomerRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CustomerRepository::class)]
#[UniqueEntity(fields: ['ice'] , message:"Ice existe déja merci de saisir un autre")]
#[ApiResource]
class Customer
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $fistName = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastName = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $mail = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $phone = null;
#[ORM\OneToOne(targetEntity: User::class, cascade: ['persist', 'remove'])]
private ?User $user = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $genre = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $ice = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $nomEntreprice = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $profession = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateNaissance = null;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Invoice::class)]
private Collection $invoices;
public function __construct()
{
$this->invoices = new ArrayCollection();
}
public function __toString()
{
return $this->fistName.' '.$this->lastName;
}
public function getId(): ?int
{
return $this->id;
}
public function getFistName(): ?string
{
return $this->fistName;
}
public function setFistName(?string $fistName): self
{
$this->fistName = $fistName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getMail(): ?string
{
return $this->mail;
}
public function setMail(?string $mail): self
{
$this->mail = $mail;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getGenre(): ?string
{
return $this->genre;
}
public function setGenre(?string $genre): self
{
$this->genre = $genre;
return $this;
}
public function getIce(): ?string
{
return $this->ice;
}
public function setIce(?string $ice): self
{
$this->ice = $ice;
return $this;
}
public function getNomEntreprice(): ?string
{
return $this->nomEntreprice;
}
public function setNomEntreprice(?string $nomEntreprice): self
{
$this->nomEntreprice = $nomEntreprice;
return $this;
}
public function getProfession(): ?string
{
return $this->profession;
}
public function setProfession(?string $profession): self
{
$this->profession = $profession;
return $this;
}
public function getDateNaissance(): ?\DateTimeInterface
{
return $this->dateNaissance;
}
public function setDateNaissance(?\DateTimeInterface $dateNaissance): self
{
$this->dateNaissance = $dateNaissance;
return $this;
}
/**
* @return Collection<int, Invoice>
*/
public function getInvoices(): Collection
{
return $this->invoices;
}
public function addInvoice(Invoice $invoice): self
{
if (!$this->invoices->contains($invoice)) {
$this->invoices->add($invoice);
$invoice->setCustomer($this);
}
return $this;
}
public function removeInvoice(Invoice $invoice): self
{
if ($this->invoices->removeElement($invoice)) {
// set the owning side to null (unless already changed)
if ($invoice->getCustomer() === $this) {
$invoice->setCustomer(null);
}
}
return $this;
}
}