<?phpnamespace Whater\Domain\Zones\Model;use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Ramsey\Uuid\Uuid;use Whater\Domain\Common\Exception\InvalidUUIDException;use Whater\Domain\Zones\Model\Town;use Whater\Domain\Zones\Model\Ubication;use Whater\Domain\User\Model\User;use Whater\Domain\Whater\Model\DistributionNetwork;use Whater\Domain\Zones\Exception\InvalidLocationInTownException;/** * Class Agrupation * * @package Whater\Domain\Zones\Model */class Agrupation implements ContainsRecordedEvents{ use EventRecorderCapabilities; /** * @var string */ private $uuid; /** * @var string */ private $slug; /** * @var string */ private $name; /** * @var Collection */ private $towns; /** * @var Collection */ private $countryAreas; /** * @var Collection */ private $organizationLicenses; /** * @var \DateTime */ private $createdAt; /** * @var \DateTime */ private $updatedAt; /** * @param string $agrupationId * @param Town $town * @param string $name * @param string $slug */ public function __construct( string $agrupationId = null, string $name, string $slug = null ) { try { $this->uuid = Uuid::fromString($agrupationId ?: Uuid::uuid4())->toString(); } catch (\InvalidArgumentException $e) { throw new InvalidUUIDException(); } $this->slug = $slug; $this->name = $name; $this->towns = new ArrayCollection(); $this->countryAreas = new ArrayCollection(); $this->organizationLicenses = new ArrayCollection(); $this->createdAt = new \DateTime(); $this->updatedAt = new \DateTime(); } public function updateAgrupationData( string $name, string $slug = null ) { $this->name = $name; $this->slug = $slug; $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 Collection */ public function towns(): Collection { return $this->towns; } /** * @return Collection */ public function countryAreas(): Collection { return $this->countryAreas; } /** * @return Collection */ public function organizationLicenses(): Collection { return $this->organizationLicenses; } /** * @return \DateTime */ public function createdAt(): \DateTime { return $this->createdAt; } /** * @return \DateTime */ public function updatedAt(): \DateTime { return $this->updatedAt; } /** * @return bool */ public function equals(Agrupation $agrupation) { return $this->id() === $agrupation->id(); }}