<?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;
use Whater\Domain\Zones\Model\Town;
use Whater\Domain\Zones\Model\Ubication;
use Whater\Domain\Whater\Model\DistributionNetwork;
use Whater\Domain\Zones\Exception\InvalidLocationInTownException;
/**
* Class Establishment
*
* @package Whater\Domain\Zones\Model
*/
class Establishment implements ContainsRecordedEvents
{
use EventRecorderCapabilities;
const ET_COMMERCIAL_ESTABLISHMENT = 'ET_COMMERCIAL_ESTABLISHMENT';// ESTABLECIMIENTO COMERCIAL
const ET_BAR_RESTAURANT_CAFETERIA = 'ET_BAR_RESTAURANT_CAFETERIA';// BAR, RESTAURANTE CAFETERÍA
const ET_RESTAURANT_CHAIN = 'ET_RESTAURANT_CHAIN';// CADENA DE RESTAURACIÓN
const ET_PRIORITIZED_BUILDING = 'ET_PRIORITIZED_BUILDING';// EDIFICIO PRIORITARIO SEGÚN EL RD 3/2023
const ET_INDIVIDUAL_ACCOMMODATION = 'ET_INDIVIDUAL_ACCOMMODATION';// ALOJAMIENTO INDIVIDUAL
const ET_CENTERS = 'ET_CENTERS';// CENTROS (COMERCIALES, DEPORTIVOS, DE NEGOCIOS)
const ET_HOTEL_CHAIN = 'ET_HOTEL_CHAIN';// CADENA HOTELERA, APARTAMENTOS, CAMPINGS
const ET_TOURISM_OFFICES = 'ET_TOURISM_OFFICES';// OFICINAS DE TURISMO, GESTOR DE DESTINOS
const ET_OTHERS = 'ET_OTHERS';//Otros, inicializamos los ya creados a otros
/**
* @var string
*/
private $uuid;
/**
* @var string
*/
private $slug;
/**
* @var string
*/
private $name;
/**
* @var Town
*/
private $town;
/**
* @var TownLocation
*/
private $townLocation;
/**
* @var Ubication
*/
private $ubication;
/**
* @var Collection
*/
private $whaterPoints;
/**
* @var float
*/
private $latitude;
/**
* @var float
*/
private $longitude;
/**
* @var string
*/
private $tipology;
/**
* @var Collection
*/
private $whaterDevices;
/**
* @var Collection
*/
private $organizationLicenses;
/**
* @var DistributionNetwork
*/
private $distributionNetwork;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var \DateTime
*/
private $updatedAt;
public function __construct(
string $establishmentId = null,
Town $town,
Ubication $ubication = null,
string $name,
string $tipology,
string $slug = null,
DistributionNetwork $distributionNetwork = null,
string $latitude = null,
string $longitude = null,
TownLocation $townLocation = null,
) {
try {
$this->uuid = Uuid::fromString($establishmentId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->slug = $slug;
$this->name = $name;
$this->tipology = $tipology;
$this->town = $town;
$this->townLocation = $townLocation;
$this->latitude = $latitude;
$this->longitude = $longitude;
if ($this->latitude == null || $this->longitude == null) {
$this->latitude = $town->latitude();
$this->longitude = $town->longitude();
}
$this->whaterPoints = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->ubication = $ubication;
if ($ubication != null && !$ubication->town()->equals($town)) {
throw new InvalidLocationInTownException();
}
$this->whaterDevices = new ArrayCollection();
$this->organizationLicenses = new ArrayCollection();
$this->distributionNetwork = $distributionNetwork;
}
public function updateEstablishmentData(
string $name,
string $tipology,
string $slug = null,
Ubication $ubication = null,
DistributionNetwork $distributionNetwork = null,
float $latitude = null,
float $longitude = null,
TownLocation $townLocation = null
) {
$this->name = $name;
$this->tipology = $tipology;
$this->slug = $slug;
if ($this->ubication != null) {
if ($ubication != null && !$ubication->town()->equals($this->town)) {
throw new InvalidLocationInTownException();
}
$this->ubication = $ubication;
}
if ($latitude != null && $longitude != null) {
$this->latitude = $latitude;
$this->longitude = $longitude;
}
if ($townLocation != null) {
$this->townLocation = $townLocation;
}
$this->updatedAt = new \DateTime();
$this->distributionNetwork = $distributionNetwork;
}
/**
* @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 Ubication
*/
public function ubication(): ?Ubication
{
return $this->ubication;
}
/**
* @return Town
*/
public function town(): Town
{
return $this->town;
}
/**
* @return TownLocation|null
*/
public function townLocation(): ?TownLocation
{
return $this->townLocation;
}
/**
* @return float|null
*/
public function latitude(): ?float
{
return $this->latitude;
}
/**
* @return float|null
*/
public function longitude(): ?float
{
return $this->longitude;
}
/**
* @return string
*/
public function tipology(): string
{
return $this->tipology;
}
/**
* @return Collection
*/
public function whaterPoints(): Collection
{
return $this->whaterPoints;
}
/**
* @return Collection
*/
public function whaterDevices(): Collection
{
return $this->whaterDevices;
}
/**
* @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 ?DistributionNetwork
*/
public function distributionNetwork(): ?DistributionNetwork
{
return $this->distributionNetwork;
}
/**
* @return bool
*/
public function equals(Establishment $establishment)
{
return $this->id() === $establishment->id();
}
}