<?php
namespace Whater\Domain\Product\Model;
use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
use Ramsey\Uuid\Uuid;
use Whater\Domain\Common\Exception\InvalidUUIDException;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
/**
* Class ProductCategory
*
* @package Whater\Domain\productCategory\Model
*/
class ProductCategory implements ContainsRecordedEvents
{
use EventRecorderCapabilities;
/**
* @var string
*/
private $uuid;
/**
* @var string
*/
private $productCategoryName;
/**
* @var string
*/
private $productCategorySlug;
/**
* @var string
*/
private $productCategoryDescription;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var null|\DateTime
*/
private $updatedAt;
/**
* @var Collection
*/
private $productCategoryChildren;
/**
* @var Collection
*/
private $products;
/**
* @var ProductCategory
*/
private $productCategoryParent;
/**
* @param string $productCategoryId
*/
public function __construct(
string $productCategoryId = null,
string $productCategoryName,
string $productCategoryDescription = null,
ProductCategory $productCategoryParent = null,
) {
try {
$this->uuid = Uuid::fromString($productCategoryId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->productCategoryName = $productCategoryName;
$this->productCategorySlug = $productCategoryName;
$this->productCategoryDescription = $productCategoryDescription;
$this->productCategoryParent = $productCategoryParent;
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->productCategoryChildren = new ArrayCollection();
}
public function editproductCategory(
string $productCategoryName,
string $productCategoryDescription = null,
string $productCategorySlug = null,
ProductCategory $productCategoryParent = null
) {
$this->productCategoryName = $productCategoryName;
$this->productCategoryDescription = $productCategoryDescription;
$this->productCategorySlug = $productCategorySlug;
$this->productCategoryParent = $productCategoryParent;
$this->updatedAt = new \DateTime();
}
/**
* @return string
*/
public function id(): string
{
return $this->uuid;
}
/**
* @return string
*/
public function productCategoryName(): string
{
return $this->productCategoryName;
}
/**
* @return string
*/
public function productCategorySlug(): string
{
return $this->productCategorySlug;
}
/**
* @return string
*/
public function productCategoryDescription(): ?string
{
return $this->productCategoryDescription;
}
/**
* @return ProductCategory
*/
public function productCategoryParent(): ?ProductCategory
{
return $this->productCategoryParent;
}
public function categoryPath(): string
{
if ($this->productCategoryParent() == null) {
return $this->productCategoryName();
} else {
return $this->productCategoryParent()->categoryPath() . ' > ' . $this->productCategoryName();
}
}
/**
* @return \DateTime
*/
public function createdAt(): \DateTime
{
return $this->createdAt;
}
/**
* @return \DateTime|null
*/
public function updatedAt()
{
return $this->updatedAt;
}
public function productCategoryChildren(): Collection
{
return $this->productCategoryChildren;
}
public function products(): Collection
{
return $this->products;
}
}