src/Domain/User/Model/OwnershipRequest.php line 20

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