<?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\User\Model\User;
/**
* Class UbicationValoration
*
* @package Whater\Domain\Whater\Model
*/
class UbicationValoration implements ContainsRecordedEvents
{
use EventRecorderCapabilities;
public const WP_MAX_VALORATION = 5;
public const WP_MIN_VALORATION = 0;
/**
* @var string
*/
private $uuid;
/**
* @var Ubication
*/
private $ubication;
/**
* @var User
*/
private $createdBy;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var int
*/
private $parameter1;
/**
* @var int
*/
private $parameter2;
/**
* @var int
*/
private $parameter3;
/**
* @var int
*/
private $parameter4;
/**
* @var bool
*/
private $isProfessionalValoration;
public function __construct(
string $ubicationValorationId = null,
Ubication $ubication,
User $createdBy,
int $parameter1 = null,
int $parameter2 = null,
int $parameter3 = null,
int $parameter4 = null,
bool $isProfessionalValoration = false
) {
try {
$this->uuid = Uuid::fromString($ubicationValorationId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->ubication = $ubication;
$this->createdBy = $createdBy;
$this->isProfessionalValoration = $isProfessionalValoration;
$this->updateValoration(
$parameter1,
$parameter2,
$parameter3,
$parameter4
);
$this->createdAt = new \DateTime();
}
public function updateValoration(
int $parameter1 = null,
int $parameter2 = null,
int $parameter3 = null,
int $parameter4 = null
): UbicationValoration {
if (!$this->ubication()->valorations()->contains($this)) {
$this->ubication()->valorations()->add($this);
}
if (!is_null($parameter1)) {
$this->parameter1 = $parameter1;
if ($this->parameter1 < UbicationValoration::WP_MIN_VALORATION) {
$this->parameter1 = UbicationValoration::WP_MIN_VALORATION;
} else if ($this->parameter1 > UbicationValoration::WP_MAX_VALORATION) {
$this->parameter1 = UbicationValoration::WP_MAX_VALORATION;
}
}
if (!is_null($parameter2)) {
$this->parameter2 = $parameter2;
if ($this->parameter2 < UbicationValoration::WP_MIN_VALORATION) {
$this->parameter2 = UbicationValoration::WP_MIN_VALORATION;
} else if ($this->parameter2 > UbicationValoration::WP_MAX_VALORATION) {
$this->parameter2 = UbicationValoration::WP_MAX_VALORATION;
}
}
if (!is_null($parameter3)) {
$this->parameter3 = $parameter3;
if ($this->parameter3 < UbicationValoration::WP_MIN_VALORATION) {
$this->parameter3 = UbicationValoration::WP_MIN_VALORATION;
} else if ($this->parameter3 > UbicationValoration::WP_MAX_VALORATION) {
$this->parameter3 = UbicationValoration::WP_MAX_VALORATION;
}
}
if (!is_null($parameter4)) {
$this->parameter4 = $parameter4;
if ($this->parameter4 < UbicationValoration::WP_MIN_VALORATION) {
$this->parameter4 = UbicationValoration::WP_MIN_VALORATION;
} else if ($this->parameter4 > UbicationValoration::WP_MAX_VALORATION) {
$this->parameter4 = UbicationValoration::WP_MAX_VALORATION;
}
}
$this->ubication()->updateValorations();
return $this;
}
/**
* @return string
*/
public function id(): string
{
return $this->uuid;
}
/**
* @return Ubication
*/
public function ubication(): Ubication
{
return $this->ubication;
}
/**
* @return User
*/
public function createdBy(): User
{
return $this->createdBy;
}
/**
* @return int
*/
public function parameter1(): ?int
{
return $this->parameter1;
}
/**
* @return int
*/
public function parameter2(): ?int
{
return $this->parameter2;
}
/**
* @return int
*/
public function parameter3(): ?int
{
return $this->parameter3;
}
/**
* @return int
*/
public function parameter4(): ?int
{
return $this->parameter4;
}
/**
* @return bool
*/
public function isProfessionalValoration(): bool
{
return $this->isProfessionalValoration;
}
/**
* @return \DateTime
*/
public function createdAt(): \DateTime
{
return $this->createdAt;
}
/**
* @return bool
*/
public function equals(UbicationValoration $ubicationValoration)
{
return $this->id() === $ubicationValoration->id();
}
}