<?php
namespace App\Entity\Shop\Product;
use App\Entity\BaseEntity;
use App\Entity\Shop\Shop\Shop;
use App\Repository\Shop\Product\ProductCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: ProductCategoryRepository::class)]
class ProductCategory extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $imageUrl = null;
#[ORM\ManyToOne(inversedBy: 'productCategories')]
#[ORM\JoinColumn(nullable: false)]
private ?Shop $shop = null;
#[ORM\ManyToMany(targetEntity: Product::class, inversedBy: 'productCategories')]
private Collection $products;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'productCategories')]
private ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $productCategories;
public function __construct()
{
parent::__construct();
$this->products = new ArrayCollection();
$this->productCategories = new ArrayCollection();
}
public function __toString()
{
return (string) $this->getName();
}
public function getId(): ?string
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getImageUrl(): ?string
{
return $this->imageUrl;
}
public function setImageUrl(?string $imageUrl): static
{
$this->imageUrl = $imageUrl;
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): static
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getProductCategories(): Collection
{
return $this->productCategories;
}
public function addProductCategory(self $productCategory): static
{
if (!$this->productCategories->contains($productCategory)) {
$this->productCategories->add($productCategory);
$productCategory->setParent($this);
}
return $this;
}
public function removeProductCategory(self $productCategory): static
{
if ($this->productCategories->removeElement($productCategory)) {
// set the owning side to null (unless already changed)
if ($productCategory->getParent() === $this) {
$productCategory->setParent(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);
}
return $this;
}
public function removeProduct(Product $product): static
{
$this->products->removeElement($product);
return $this;
}
}