<?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\DistributionNetworkValorationImage;
use Whater\Domain\Media\Model\WhaterValorationImage;
use Whater\Domain\User\Model\User;
/**
* Class DistributionNetworkValoration
*
* @package Whater\Domain\Whater\Model
*/
class DistributionNetworkValoration implements ContainsRecordedEvents
{
use EventRecorderCapabilities;
public const DN_MAX_VALORATION = 5;
public const DN_MIN_VALORATION = 0;
public const DN_QUALITY_ACCEPTABLE_VALORATION = "DN_QUALITY_ACCEPTABLE_VALORATION";
public const DN_QUALITY_NOT_ACCEPTABLE_VALORATION = "DN_QUALITY_NOT_ACCEPTABLE_VALORATION";
public const DN_QUALITY_NEEDS_IMPROVEMENT_VALORATION = "DN_QUALITY_NEEDS_IMPROVEMENT_VALORATION";
/**
* @var string
*/
private $uuid;
/**
* @var DistributionNetwork
*/
private $distributionNetwork;
/**
* @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 DistributionNetworkValorationImage
*/
private $commentImage;
/**
* @var bool
*/
private $isProfessionalValoration;
public function __construct(
string $distributionNetworkPointValorationId = null,
DistributionNetwork $distributionNetwork,
User $createdBy,
string $colorValoration = null,
string $tasteValoration = null,
string $smellValoration = null,
string $turbidityValoration = null,
string $generalValoration = null,
bool $isProfessionalValoration = false,
DistributionNetworkValorationImage $commentImage = null
) {
try {
$this->uuid = Uuid::fromString($distributionNetworkPointValorationId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->distributionNetwork = $distributionNetwork;
$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
): DistributionNetworkValoration {
if (!$this->distributionNetwork()->valorations()->contains($this)) {
$this->distributionNetwork()->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->distributionNetwork()->updateValorations();
return $this;
}
public function updateComment(
string $userCommentText = null,
string $responseCommentText = null,
\DateTime $responseCommentAt = null,
bool $hideUserComment = false
): DistributionNetworkValoration {
$this->userCommentText = $userCommentText;
$this->responseCommentText = $responseCommentText;
$this->responseCommentAt = $responseCommentAt;
$this->hideUserComment = $hideUserComment;
return $this;
}
/**
* @return string
*/
public function id(): string
{
return $this->uuid;
}
/**
* @return DistributionNetwork
*/
public function distributionNetwork(): DistributionNetwork
{
return $this->distributionNetwork;
}
/**
* @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 DistributionNetworkValorationImage
*/
public function commentImage(): ?DistributionNetworkValorationImage
{
return $this->commentImage;
}
/**
* @return \DateTime
*/
public function createdAt(): \DateTime
{
return $this->createdAt;
}
/**
* @return bool
*/
public function equals(DistributionNetworkValoration $distributionNetworkValoration)
{
return $this->id() === $distributionNetworkValoration->id();
}
}