<?php
namespace Whater\Domain\Product\Model;
use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Ramsey\Uuid\Uuid;
use Whater\Domain\Common\Exception\InvalidUUIDException;
/**
* Class ProductAttribute
*
* @package Whater\Domain\productAttribute\Model
*/
class ProductAttribute implements ContainsRecordedEvents
{
use EventRecorderCapabilities;
/**
* @var string
*/
private $uuid;
/**
* @var string
*/
private $productAttributeName;
/**
* @var string
*/
private $productAttributeSlug;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var null|\DateTime
*/
private $updatedAt;
/**
* @var array
*/
private $productAttributeTerms;
/**
* @var Collection
*/
private $products;
/**
* @param string $productAttributeId
*/
public function __construct(
string $productAttributeId = null,
string $productAttributeName
) {
try {
$this->uuid = Uuid::fromString($productAttributeId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->productAttributeName = $productAttributeName;
$this->productAttributeSlug = $productAttributeName;
$this->products = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
public function editproductAttribute(
string $productAttributeName,
string $productAttributeSlug = null,
array $productAttributeTerms = null
) {
$this->productAttributeName = $productAttributeName;
$this->productAttributeSlug = $productAttributeSlug;
$this->productAttributeTerms = $productAttributeTerms;
$this->updatedAt = new \DateTime();
}
/**
* @return string
*/
public function id(): string
{
return $this->uuid;
}
/**
* @return string
*/
public function productAttributeName(): string
{
return $this->productAttributeName;
}
/**
* @return string
*/
public function productAttributeSlug(): string
{
return $this->productAttributeSlug;
}
/**
* @return Collection
*/
public function products(): Collection
{
return $this->products;
}
/**
* @return \DateTime
*/
public function createdAt(): \DateTime
{
return $this->createdAt;
}
/**
* @return \DateTime|null
*/
public function updatedAt()
{
return $this->updatedAt;
}
public function productAttributeTerms(): ?array
{
return $this->productAttributeTerms;
}
/**
* @return bool
*/
public function equals(ProductAttribute $productAttribute)
{
return $this->id() === $productAttribute->id();
}
}