<?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\Agrupation;/** * Class CountryArea * * @package Whater\Domain\Zones\Model */class CountryArea implements ContainsRecordedEvents{ use EventRecorderCapabilities; const IDS_SINAC_PROVINCIA = 'sinac_codProvincia'; /** * @var string */ private $uuid; /** * @var string */ private $slug; /** * @var array */ private $externalIds; /** * @var string */ private $name; /** * @var Country */ private $country; /** * @var Collection */ private $towns; /** * @var Collection */ private $townLocations; /** * @var Collection */ private $organizationLicenses; /** * @var Collection */ private $products; /** * @var Collection */ private $agrupations; /** * @var \DateTime */ private $createdAt; /** * @var \DateTime */ private $updatedAt; /** * @var string */ private $adminCode; /** * @var string */ private $geoNameId; /** * @var int */ private $population; /** * @param string $areaId * @param Country $country * @param string $name * @param string $isoCode */ public function __construct( string $areaId = null, Country $country, string $name, string $slug = null, array $externalIds = [] ) { try { $this->uuid = Uuid::fromString($areaId ?: Uuid::uuid4())->toString(); } catch (\InvalidArgumentException $e) { throw new InvalidUUIDException(); } $this->country = $country; $this->slug = $slug; $this->externalIds = $externalIds; $this->name = $name; $this->towns = new ArrayCollection(); $this->townLocations = new ArrayCollection(); $this->organizationLicenses = new ArrayCollection(); $this->products = new ArrayCollection(); $this->agrupations = new ArrayCollection(); $this->createdAt = new \DateTime(); $this->updatedAt = new \DateTime(); } public function updateCountryAreaData( string $name, string $slug = null, string $adminCode = null, string $geoNameId = null, int $population = null ) { $this->name = $name; $this->slug = $slug; $this->adminCode = $adminCode; $this->geoNameId = $geoNameId; $this->population = $population; $this->updatedAt = new \DateTime(); } public function addAgrupation( Agrupation $agrupation = null ) { if(!$this->agrupations()){ $this->agrupations = new ArrayCollection(); } $this->agrupations->add($agrupation); $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 adminCode(): ?string { return $this->adminCode; } /** * @return string */ public function geoNameId(): ?string { return $this->geoNameId; } /** * @return int|null */ public function population(): ?int { return $this->population; } /** * @return string */ public function slug(): ?string { return $this->slug; } /** * @return array */ public function externalIds(): array { return $this->externalIds; } /** * @return Country */ public function country(): Country { return $this->country; } /** * @return Collection */ public function towns(): Collection { return $this->towns; } /** * @return Collection */ public function townLocations(): Collection { return $this->townLocations; } /** * @return Collection */ public function organizationLicenses(): Collection { return $this->organizationLicenses; } /** * @return Collection */ public function products(): Collection { return $this->products; } /** * @return Collection */ public function agrupations(): Collection { return $this->agrupations; } /** * @return \DateTime */ public function createdAt(): \DateTime { return $this->createdAt; } /** * @return \DateTime */ public function updatedAt(): \DateTime { return $this->updatedAt; } /** * @return bool */ public function equals(CountryArea $countryArea) { return $this->id() === $countryArea->id(); }}