<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\OrderRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: OrderRepository::class)]
#[ORM\Table(name: '`order`')]
/**
* @ApiResource(
* normalizationContext={"groups"={"order:read"}},
* denormalizationContext={"groups"={"order:write"}}
* )
*/
class Order
{
public const STATUS = [
'PENDING' => 'PENDING',
'REJECTED' => 'REJECTED',
'SHIPPED' => 'SHIPPED',
'PAYED' => 'PAYED',
];
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['order:write', 'order:read'])]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'orders')]
#[Groups(['order:write', 'order:read'])]
private ?User $patient = null;
#[ORM\ManyToOne(inversedBy: 'orders')]
#[Groups(['order:write', 'order:read'])]
private ?User $pharmacy = null;
#[ORM\OneToMany(mappedBy: 'commande', targetEntity: Product::class)]
private Collection $product;
#[ORM\Column]
#[Groups(['order:write', 'order:read'])]
private ?\DateTimeImmutable $created_at = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(['order:write', 'order:read'])]
private ?\DateTimeInterface $updated_at = null;
#[ORM\Column(length: 255)]
#[Groups(['order:write', 'order:read'])]
private ?string $status = 'PENDING';
public function __construct()
{
$this->product = new ArrayCollection();
$this->created_at = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getPatient(): ?User
{
return $this->patient;
}
public function setPatient(?User $patient): static
{
$this->patient = $patient;
return $this;
}
public function getPharmacy(): ?User
{
return $this->pharmacy;
}
public function setPharmacy(?User $pharmacy): static
{
$this->pharmacy = $pharmacy;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProduct(): Collection
{
return $this->product;
}
public function addProduct(Product $product): static
{
if (!$this->product->contains($product)) {
$this->product->add($product);
$product->setCommande($this);
}
return $this;
}
public function removeProduct(Product $product): static
{
if ($this->product->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getCommande() === $this) {
$product->setCommande(null);
}
}
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): static
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): static
{
$this->updated_at = $updated_at;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
}