<?phpnamespace Whater\Domain\User\Model;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Ramsey\Uuid\Uuid;use Whater\Domain\Common\Exception\InvalidUUIDException;use Whater\Domain\User\Exception\InvalidNfcClassException;use Whater\Domain\Whater\Model\WhaterOrganization;/** * Class UserNfc * * @package Whater\Domain\User\Model */class UserNfc{ public const NFC_CLASS_BOTTLE = 'NFC_CLASS_BOTTLE'; public const NFC_CLASS_BRACELET = 'NFC_CLASS_BRACELET'; public const NFC_CLASS_SMARTPHONE = 'NFC_CLASS_SMARTPHONE'; public const NFC_CLASS_SMARTWATCH = 'NFC_CLASS_SMARTWATCH'; public const NFC_CLASS_CARD = 'NFC_CLASS_CARD'; /** * @var string */ private $uuid; /** * @var string */ private $nfcId; /** * @var string */ private $nfcLabel; /** * @var string */ private $nfcClass; /** * @var WhaterOrganization */ private $whaterOrganization; /** * @var Collection */ private $whaterRefills; /** * @var User */ private $user; /** * @var \DateTime */ private $createdAt; /** * @var \DateTime */ private $updatedAt; public function __construct( ?string $userNfcId = null, WhaterOrganization $whaterOrganization, User $user, string $nfcId, string $nfcClass = UserNfc::NFC_CLASS_BOTTLE ) { try { $this->uuid = Uuid::fromString($userNfcId ?: Uuid::uuid4())->toString(); } catch (\InvalidArgumentException $e) { throw new InvalidUUIDException(); } $this->whaterOrganization = $whaterOrganization; $this->user = $user; $this->nfcId = $nfcId; switch ($nfcClass) { case UserNfc::NFC_CLASS_BOTTLE: case UserNfc::NFC_CLASS_BRACELET: case UserNfc::NFC_CLASS_CARD: case UserNfc::NFC_CLASS_SMARTWATCH: case UserNfc::NFC_CLASS_SMARTPHONE: $this->nfcClass = $nfcClass; break; default: throw new InvalidNfcClassException(); } $this->whaterRefills = new ArrayCollection(); $this->createdAt = new \DateTime(); $this->updatedAt = $this->createdAt; } public function updateNfc( string $nfcId, string $nfcClass, ?string $nfcLabel = null, ?User $user = null, ?WhaterOrganization $whaterOrganization = null ) { $this->nfcId = $nfcId; $this->nfcClass = $nfcClass; $this->nfcLabel = $nfcLabel; if ($user != null) { $this->user = $user; } if ($whaterOrganization != null) { $this->whaterOrganization = $whaterOrganization; } $this->updatedAt = new \DateTime(); } /** * @return string */ public function id(): string { return $this->uuid; } /** * @return string */ public function nfcId(): string { return $this->nfcId; } /** * @return string */ public function nfcClass(): string { return $this->nfcClass; } /** * @return WhaterOrganization */ public function whaterOrganization(): WhaterOrganization { return $this->whaterOrganization; } /** * @return User */ public function user(): User { return $this->user; } /** * @return Collection */ public function whaterRefills(): Collection { return $this->whaterRefills; } /** * @return string */ public function nfcLabel(): ?string { return $this->nfcLabel; } /** * @return \DateTime */ public function createdAt(): \DateTime { return $this->createdAt; } /** * @return \DateTime */ public function updatedAt(): \DateTime { return $this->updatedAt; }}