<?phpnamespace Whater\Domain\Whater\Model;use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;use Doctrine\Common\Collections\Collection;use Ramsey\Uuid\Uuid;use Whater\Domain\Common\Exception\InvalidUUIDException;/** * Class WhaterPointAttribute * * @package Whater\Domain\Whater\Model */class WhaterPointAttributeType implements ContainsRecordedEvents{ use EventRecorderCapabilities; const ATTR_VALUE_TEXT = 'ATTR_TYPE_TEXT'; const ATTR_VALUE_FLOAT = 'ATTR_TYPE_FLOAT'; const ATTR_VALUE_CHOICES = 'ATTR_TYPE_CHOICES'; /** * @var string */ private $uuid; /** * @var \DateTime */ private $createdAt; /** * @var \DateTime */ private $updatedAt; /** * @var string */ private $name; /** * @var string */ private $slug; /** * @var string */ private $attributeType; /** * @var Collection */ private $choices; public function __construct( string $whaterPointAttributeTypeId = null, string $name, string $slug, string $attributeType, Collection $choices = null ) { try { $this->uuid = Uuid::fromString($whaterPointAttributeTypeId ?: Uuid::uuid4())->toString(); } catch (\InvalidArgumentException $e) { throw new InvalidUUIDException(); } $this->name = $name; $this->slug = $slug; $this->attributeType = $attributeType; if ($attributeType == WhaterPointAttributeType::ATTR_VALUE_CHOICES) { $this->updateAttributeTypeChoices($choices); } $this->createdAt = new \DateTime(); $this->updatedAt = new \DateTime(); } public function updateAttributeTypeChoices( Collection $choices ) { $this->choices = $choices; $this->updatedAt = new \DateTime(); } /** * @return string */ public function id(): string { return $this->uuid; } /** * @return string */ public function name(): string { return $this->name; } /** * @return string */ public function slug(): string { return $this->slug; } /** * @return string */ public function attributeType(): string { return $this->attributeType; } /** * @return Collection|null */ public function choices(): ?Collection { return $this->choices; } /** * @return \DateTime */ public function createdAt(): \DateTime { return $this->createdAt; } /** * @return \DateTime */ public function updatedAt(): \DateTime { return $this->updatedAt; } /** * @return bool */ public function equals(WhaterPointAttributeType $whaterPointAttributeType) { return $this->id() === $whaterPointAttributeType->id(); }}