<?php
namespace 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;
/**
* Class Country
*
* @package Whater\Domain\Zones\Model
*/
class Country implements ContainsRecordedEvents
{
use EventRecorderCapabilities;
/**
* @var string
*/
private $uuid;
/**
* @var string
*/
private $isoCode;
/**
* @var string
*/
private $name;
/**
* @var Collection
*/
private $countryAreas;
/**
* @var Collection
*/
private $towns;
/**
* @var Collection
*/
private $townLocations;
/**
* @var Collection
*/
private $organizationLicenses;
/**
* @var Collection
*/
private $products;
/**
* @var Collection
*/
private $distributionNetworks;
/**
* @var Collection
*/
private $whaterOrganizations;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var \DateTime
*/
private $updatedAt;
/**
* @var string
*/
private $isoCode3;
/**
* @var string
*/
private $isoNumeric;
/**
* @var string
*/
private $capital;
/**
* @var int
*/
private $areaInKm2;
/**
* @var int
*/
private $population;
/**
* @var string
*/
private $continent;
/**
* @var string
*/
private $geoNameId;
/**
* @var float
*/
private $latitude;
/**
* @var float
*/
private $longitude;
/**
* @param string $countryId
* @param string $isoCode
* @param string $name
*/
public function __construct(
string $countryId = null,
string $isoCode,
string $name
) {
try {
$this->uuid = Uuid::fromString($countryId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->isoCode = $isoCode;
$this->name = $name;
$this->countryAreas = new ArrayCollection();
$this->towns = new ArrayCollection();
$this->townLocations = new ArrayCollection();
$this->organizationLicenses = new ArrayCollection();
$this->products = new ArrayCollection();
$this->distributionNetworks = new ArrayCollection();
$this->whaterOrganizations = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->updatedAt = $this->createdAt;
}
public function updateCountryData(
string $isoCode,
string $name,
string $isoCode3 = null,
string $isoNumeric = null,
string $geoNameId = null,
string $continent = null,
string $capital = null,
string $areaInKm2 = null,
string $population = null,
float $latitude = null,
float $longitude = null
) {
$this->isoCode = $isoCode;
$this->name = $name;
$this->isoCode3 = $isoCode3;
$this->isoNumeric = $isoNumeric;
$this->geoNameId = $geoNameId;
$this->continent = $continent;
$this->capital = $capital;
$this->areaInKm2 = $areaInKm2;
$this->population = $population;
if ($latitude != null && $longitude != null) {
$this->latitude = $latitude;
$this->longitude = $longitude;
}
$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 isoCode(): string
{
return $this->isoCode;
}
/**
* @return string
*/
public function isoCode3(): ?string
{
return $this->isoCode3;
}
/**
* @return string
*/
public function isoNumeric(): ?string
{
return $this->isoNumeric;
}
/**
* @return string
*/
public function geoNameId(): ?string
{
return $this->geoNameId;
}
/**
* @return string
*/
public function continent(): ?string
{
return $this->continent;
}
/**
* @return string
*/
public function capital(): ?string
{
return $this->capital;
}
/**
* @return integer|null
*/
public function areaInKm2(): ?int
{
return $this->areaInKm2;
}
/**
* @return integer|null
*/
public function population(): ?int
{
return $this->population;
}
/**
* @return float
*/
public function latitude(): float
{
if ($this->latitude == null) {
return 0;
}
return $this->latitude;
}
/**
* @return float
*/
public function longitude(): float
{
if ($this->longitude == null) {
return 0;
}
return $this->longitude;
}
/**
* @return Collection
*/
public function whaterOrganizations(): Collection
{
return $this->whaterOrganizations;
}
/**
* @return Collection
*/
public function distributionNetworks(): Collection
{
return $this->distributionNetworks;
}
/**
* @return Collection
*/
public function countryAreas(): Collection
{
return $this->countryAreas;
}
/**
* @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 \DateTime
*/
public function createdAt(): \DateTime
{
return $this->createdAt;
}
/**
* @return \DateTime
*/
public function updatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @return bool
*/
public function equals(Country $country)
{
return $this->id() === $country->id();
}
}