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

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