<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\StorageElementRepository;
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: StorageElementRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['storage_element:read']],
denormalizationContext: ['groups' => ['storage_element:write']],
order: ['id' => 'DESC']
)]
class StorageElement
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['storage:read', 'storage:write', 'storage_element:read', 'storage_element:write', 'product:read', 'order:read', 'order_product:read', 'order_product:read', 'pre_order_product:read', 'pre_order:read'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['storage:read', 'storage:write', 'storage_element:read', 'storage_element:write','product:read'])]
private ?string $name = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(['storage:read', 'storage:write', 'storage_element:read', 'storage_element:write'])]
private ?\DateTimeInterface $dateEntered = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['storage:read', 'storage:write', 'storage_element:read', 'storage_element:write'])]
private ?string $description = null;
#[ORM\ManyToOne(inversedBy: 'storageElements')]
#[Groups(['storage_element:read', 'storage_element:write', 'product:read', 'order_product:read'])]
private ?Storage $storage = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'storageElements')]
private ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $storageElements;
#[ORM\Column(nullable: true)]
#[Groups(['storage:read', 'storage:write', 'storage_element:read', 'storage_element:write', 'product:read', 'order:read', 'order_product:read', 'order_product:read', 'pre_order_product:read', 'pre_order:read'])]
private ?bool $isMain = null;
#[ORM\Column(length: 50, nullable: true)]
#[Groups(['storage:read', 'storage:write', 'storage_element:read', 'storage_element:write', 'product:read', 'order:read', 'order_product:read', 'order_product:read', 'pre_order_product:read', 'pre_order:read'])]
private ?string $c1Id = null;
#[ORM\OneToMany(mappedBy: 'storageElement', targetEntity: Products::class)]
private Collection $products;
public function __construct()
{
$this->storageElements = new ArrayCollection();
$this->products = 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 getDateEntered(): ?\DateTimeInterface
{
return $this->dateEntered;
}
public function setDateEntered(?\DateTimeInterface $dateEntered): self
{
$this->dateEntered = $dateEntered;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getStorage(): ?Storage
{
return $this->storage;
}
public function setStorage(?Storage $storage): self
{
$this->storage = $storage;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getStorageElements(): Collection
{
return $this->storageElements;
}
public function addStorageElement(self $storageElement): self
{
if (!$this->storageElements->contains($storageElement)) {
$this->storageElements->add($storageElement);
$storageElement->setParent($this);
}
return $this;
}
public function removeStorageElement(self $storageElement): self
{
if ($this->storageElements->removeElement($storageElement)) {
// set the owning side to null (unless already changed)
if ($storageElement->getParent() === $this) {
$storageElement->setParent(null);
}
}
return $this;
}
public function isIsMain(): ?bool
{
return $this->isMain;
}
public function setIsMain(?bool $isMain): self
{
$this->isMain = $isMain;
return $this;
}
public function getC1Id(): ?string
{
return $this->c1Id;
}
public function setC1Id(?string $c1Id): self
{
$this->c1Id = $c1Id;
return $this;
}
/**
* @return Collection<int, Products>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Products $product): self
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setStorageElement($this);
}
return $this;
}
public function removeProduct(Products $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getStorageElement() === $this) {
$product->setStorageElement(null);
}
}
return $this;
}
}