<?php
namespace Whater\Domain\Whater\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\Media\Model\WhaterValorationImage;
use Whater\Domain\User\Model\User;
/**
* Class WhaterValoration
*
* @package Whater\Domain\Whater\Model
*/
class WhaterValoration implements ContainsRecordedEvents
{
use EventRecorderCapabilities;
public const WP_MAX_VALORATION = 5;
public const WP_MIN_VALORATION = 0;
public const WP_QUALITY_ACCEPTABLE_VALORATION = "WP_QUALITY_ACCEPTABLE_VALORATION";
public const WP_QUALITY_NOT_ACCEPTABLE_VALORATION = "WP_QUALITY_NOT_ACCEPTABLE_VALORATION";
public const WP_QUALITY_NEEDS_IMPROVEMENT_VALORATION = "WP_QUALITY_NEEDS_IMPROVEMENT_VALORATION";
/**
* @var string
*/
private $uuid;
/**
* @var WhaterPoint
*/
private $whaterPoint;
/**
* @var User
*/
private $createdBy;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var string
*/
private $colorValoration;
/**
* @var string
*/
private $tasteValoration;
/**
* @var string
*/
private $smellValoration;
/**
* @var string
*/
private $turbidityValoration;
/**
* @var string
*/
private $generalValoration;
/**
* @var string
*/
private $userCommentText;
/**
* @var string
*/
private $responseCommentText;
/**
* @var \DateTime
*/
private $responseCommentAt;
/**
* @var bool
*/
private $hideUserComment;
/**
* @var WhaterValorationImage
*/
private $commentImage;
/**
* @var bool
*/
private $isProfessionalValoration;
public function __construct(
string $whaterPointValorationId = null,
WhaterPoint $whaterPoint,
User $createdBy,
string $colorValoration = null,
string $tasteValoration = null,
string $smellValoration = null,
string $turbidityValoration = null,
string $generalValoration = null,
bool $isProfessionalValoration = false,
WhaterValorationImage $commentImage = null
) {
try {
$this->uuid = Uuid::fromString($whaterPointValorationId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->whaterPoint = $whaterPoint;
$this->createdBy = $createdBy;
$this->isProfessionalValoration = $isProfessionalValoration;
$this->hideUserComment = true;
$this->commentImage = $commentImage;
$this->createdAt = new \DateTime();
$this->updateValoration(
$colorValoration,
$tasteValoration,
$smellValoration,
$turbidityValoration,
$generalValoration
);
}
public function updateValoration(
string $colorValoration = null,
string $tasteValoration = null,
string $smellValoration = null,
string $turbidityValoration = null,
string $generalValoration = null
): WhaterValoration {
if (!$this->whaterPoint()->valorations()->contains($this)) {
$this->whaterPoint()->valorations()->add($this);
}
if (!is_null($colorValoration)) {
$this->colorValoration = $colorValoration;
}
if (!is_null($tasteValoration)) {
$this->tasteValoration = $tasteValoration;
}
if (!is_null($smellValoration)) {
$this->smellValoration = $smellValoration;
}
if (!is_null($turbidityValoration)) {
$this->turbidityValoration = $turbidityValoration;
}
if (!is_null($generalValoration)) {
$this->generalValoration = $generalValoration;
}
$this->whaterPoint()->updateValorations();
return $this;
}
public function updateComment(
string $userCommentText = null,
string $responseCommentText = null,
\DateTime $responseCommentAt = null,
bool $hideUserComment = false
): WhaterValoration {
$this->userCommentText = $userCommentText;
$this->responseCommentText = $responseCommentText;
$this->responseCommentAt = $responseCommentAt;
$this->hideUserComment = $hideUserComment;
return $this;
}
/**
* @return string
*/
public function id(): string
{
return $this->uuid;
}
/**
* @return WhaterPoint
*/
public function whaterPoint(): WhaterPoint
{
return $this->whaterPoint;
}
/**
* @return User
*/
public function createdBy(): User
{
return $this->createdBy;
}
/**
* @return string
*/
public function colorValoration(): ?string
{
return $this->colorValoration;
}
/**
* @return string
*/
public function tasteValoration(): ?string
{
return $this->tasteValoration;
}
/**
* @return string
*/
public function smellValoration(): ?string
{
return $this->smellValoration;
}
/**
* @return string
*/
public function turbidityValoration(): ?string
{
return $this->turbidityValoration;
}
/**
* @return string
*/
public function generalValoration(): ?string
{
return $this->generalValoration;
}
/**
* @return bool
*/
public function isProfessionalValoration(): bool
{
return $this->isProfessionalValoration;
}
/**
* @return string
*/
public function userCommentText(): ?string
{
return $this->userCommentText;
}
/**
* @return string
*/
public function responseCommentText(): ?string
{
return $this->responseCommentText;
}
/**
* @return \DateTime
*/
public function responseCommentAt(): ?\DateTime
{
return $this->responseCommentAt;
}
/**
* @return bool
*/
public function hideUserComment(): bool
{
return $this->hideUserComment;
}
/**
* @return WhaterValorationImage
*/
public function commentImage(): ?WhaterValorationImage
{
return $this->commentImage;
}
/**
* @return \DateTime
*/
public function createdAt(): \DateTime
{
return $this->createdAt;
}
/**
* @return bool
*/
public function equals(WhaterValoration $whaterValoration)
{
return $this->id() === $whaterValoration->id();
}
}