<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ApiResource(
itemOperations: ['get' => [
'normalization_context' => ['groups' => ['read:User:collection', 'read:User:item', 'read:User']]
]],
denormalizationContext: ['groups' => ['read:User:collection']],
normalizationContext: ['groups' => ['read:User:collection']]
)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read:User:collection', 'read:User'])]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
#[
Groups(['read:User:collection', 'read:User']),
Email(message: 'Email Incorrect')
]
private ?string $email = null;
#[ORM\Column]
#[Groups(['read:User:collection'])]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
#[
Groups(['read:User:collection']),
Length(min: 4),
]
private ?string $password = null;
#[ORM\OneToMany(mappedBy: 'patient', targetEntity: Prescription::class)]
private Collection $prescriptions;
#[ORM\ManyToOne(inversedBy: 'pharmacy')]
private ?Subscription $subscription = null;
#[ORM\OneToMany(mappedBy: 'patient', targetEntity: Order::class)]
private Collection $orders;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Schedule::class)]
private Collection $schedules;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Service::class)]
private Collection $services;
#[ORM\OneToMany(mappedBy: 'pharmacy', targetEntity: Product::class, cascade: ["persist", "remove"])]
//#[Groups(['user:write', 'user:read'])]
private Collection $products;
#[ORM\Column(length: 255)]
#[
Groups(['read:User:collection', 'read:User']),
Length(min: 3,minMessage: 'Nom trop court')
]
private ?string $fullname = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:User:collection', 'read:User'])]
private ?string $profil_url = null;
#[ORM\Column(length: 255)]
#[
Groups(['read:User:collection', 'read:User']),
Length(min: 10,minMessage: 'trop court')
]
private ?string $phone_number = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:User:collection'])]
private ?string $site_web = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:User:collection'])]
private ?string $tag_line = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['read:User:item'])]
private ?string $description = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[Groups(['write:Speciality'])]
private ?Speciality $speciality = null;
public function __construct()
{
$this->prescriptions = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->schedules = new ArrayCollection();
$this->services = new ArrayCollection();
$this->products = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return Collection<int, Prescription>
*/
public function getPrescriptions(): Collection
{
return $this->prescriptions;
}
public function addPrescription(Prescription $prescription): static
{
if (!$this->prescriptions->contains($prescription)) {
$this->prescriptions->add($prescription);
$prescription->setPatient($this);
}
return $this;
}
public function removePrescription(Prescription $prescription): static
{
if ($this->prescriptions->removeElement($prescription)) {
// set the owning side to null (unless already changed)
if ($prescription->getPatient() === $this) {
$prescription->setPatient(null);
}
}
return $this;
}
public function getSubscription(): ?Subscription
{
return $this->subscription;
}
public function setSubscription(?Subscription $subscription): static
{
$this->subscription = $subscription;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): static
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setPatient($this);
}
return $this;
}
public function removeOrder(Order $order): static
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getPatient() === $this) {
$order->setPatient(null);
}
}
return $this;
}
/**
* @return Collection<int, Schedule>
*/
public function getSchedules(): Collection
{
return $this->schedules;
}
public function addSchedule(Schedule $schedule): static
{
if (!$this->schedules->contains($schedule)) {
$this->schedules->add($schedule);
$schedule->setUser($this);
}
return $this;
}
public function removeSchedule(Schedule $schedule): static
{
if ($this->schedules->removeElement($schedule)) {
// set the owning side to null (unless already changed)
if ($schedule->getUser() === $this) {
$schedule->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Service>
*/
public function getServices(): Collection
{
return $this->services;
}
public function addService(Service $service): static
{
if (!$this->services->contains($service)) {
$this->services->add($service);
$service->setUser($this);
}
return $this;
}
public function removeService(Service $service): static
{
if ($this->services->removeElement($service)) {
// set the owning side to null (unless already changed)
if ($service->getUser() === $this) {
$service->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): static
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setPharmacy($this);
}
return $this;
}
public function removeProduct(Product $product): static
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getPharmacy() === $this) {
$product->setPharmacy(null);
}
}
return $this;
}
public function getFullname(): ?string
{
return $this->fullname;
}
public function setFullname(string $fullname): static
{
$this->fullname = $fullname;
return $this;
}
public function getProfilUrl(): ?string
{
return $this->profil_url;
}
public function setProfilUrl(?string $profil_url): static
{
$this->profil_url = $profil_url;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phone_number;
}
public function setPhoneNumber(string $phone_number): static
{
$this->phone_number = $phone_number;
return $this;
}
public function getSiteWeb(): ?string
{
return $this->site_web;
}
public function setSiteWeb(?string $site_web): static
{
$this->site_web = $site_web;
return $this;
}
public function getTagLine(): ?string
{
return $this->tag_line;
}
public function setTagLine(?string $tag_line): static
{
$this->tag_line = $tag_line;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getSpeciality(): ?Speciality
{
return $this->speciality;
}
public function setSpeciality(?Speciality $speciality): static
{
$this->speciality = $speciality;
return $this;
}
}