src/Domain/Whater/Model/WhaterRefill.php line 16

Open in your IDE?
  1. <?php
  2. namespace Whater\Domain\Whater\Model;
  3. use Ramsey\Uuid\Uuid;
  4. use Whater\Domain\Common\Exception\InvalidUUIDException;
  5. use Whater\Domain\User\Model\User;
  6. use Whater\Domain\Product\Model\CartOrder;
  7. use Whater\Domain\User\Model\UserNfc;
  8. /**
  9. * Class WhaterRefill
  10. *
  11. * @package Whater\Domain\Whater\Model
  12. */
  13. class WhaterRefill
  14. {
  15. public const DEFAULT_MILLIMETERS = 100;
  16. /**
  17. * @var string
  18. */
  19. private $uuid;
  20. /**
  21. * @var WhaterPoint
  22. */
  23. private $whaterPoint;
  24. /**
  25. * @var UserNfc
  26. */
  27. private $userNfc;
  28. /**
  29. * @var CartOrder
  30. */
  31. private $cartOrder;
  32. /**
  33. * @var User
  34. */
  35. private $user;
  36. /**
  37. * @var float
  38. */
  39. private $milliliters;
  40. /**
  41. * @var \DateTime
  42. */
  43. private $createdAt;
  44. /**
  45. * @var \DateTime
  46. */
  47. private $updatedAt;
  48. /**
  49. * @var bool
  50. */
  51. private $confirmed;
  52. /**
  53. * @param string $whaterRefill
  54. * @param Whaterpoint $whaterPoint
  55. * @param float $latitude
  56. * @param float $longitude
  57. * @param DistributionNetwork $distributionNetwork
  58. */
  59. public function __construct(
  60. ?string $whaterRefillId = null,
  61. WhaterPoint $whaterPoint,
  62. ?User $user = null,
  63. ?CartOrder $cartOrder = null,
  64. float $milliliters = WhaterRefill::DEFAULT_MILLIMETERS,
  65. ?UserNfc $userNfc = null
  66. ) {
  67. try {
  68. $this->uuid = Uuid::fromString($whaterRefillId ?: Uuid::uuid4())->toString();
  69. } catch (\InvalidArgumentException $e) {
  70. throw new InvalidUUIDException();
  71. }
  72. $this->whaterPoint = $whaterPoint;
  73. $this->user = $user;
  74. $this->cartOrder = $cartOrder;
  75. $this->milliliters = $milliliters;
  76. $this->userNfc = $userNfc;
  77. $this->confirmed = false;
  78. $this->createdAt = new \DateTime();
  79. $this->updatedAt = $this->createdAt;
  80. }
  81. public function confirmRefill(
  82. bool $confirmed
  83. ) {
  84. $this->confirmed = $confirmed;
  85. $this->updatedAt = new \DateTime();
  86. return $this;
  87. }
  88. /**
  89. * @return string
  90. */
  91. public function id(): string
  92. {
  93. return $this->uuid;
  94. }
  95. /**
  96. * @return WhaterPoint
  97. */
  98. public function whaterPoint(): WhaterPoint
  99. {
  100. return $this->whaterPoint;
  101. }
  102. /**
  103. * @return User
  104. */
  105. public function user(): ?User
  106. {
  107. return $this->user;
  108. }
  109. /**
  110. * @return UserNfc
  111. */
  112. public function userNfc(): ?UserNfc
  113. {
  114. return $this->userNfc;
  115. }
  116. /**
  117. * @return CartOrder
  118. */
  119. public function cartOrder(): ?CartOrder
  120. {
  121. return $this->cartOrder;
  122. }
  123. /**
  124. * @return float
  125. */
  126. public function milliliters(): float
  127. {
  128. return $this->milliliters;
  129. }
  130. /**
  131. * @return bool
  132. */
  133. public function confirmed(): bool
  134. {
  135. return $this->confirmed;
  136. }
  137. /**
  138. * @return \DateTime
  139. */
  140. public function createdAt(): \DateTime
  141. {
  142. return $this->createdAt;
  143. }
  144. /**
  145. * @return \DateTime
  146. */
  147. public function updatedAt(): \DateTime
  148. {
  149. return $this->updatedAt;
  150. }
  151. }