<?php
namespace Whater\Domain\Whater\Model;
use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
use InvalidArgumentException;
use Ramsey\Uuid\Uuid;
use Whater\Domain\Common\Exception\InvalidUUIDException;
/**
* Class AnalyticalParameter
*
* @package Whater\Domain\Whater\Model
*/
class AnalyticalParameter implements ContainsRecordedEvents
{
use EventRecorderCapabilities;
// Qualities Constants
public const QUALITY_IMPROVE_PERCEPTION = 'IMPROVE_PERCEPTION';
public const QUALITY_BIOLOGICAL_CONTAMINATION = 'BIOLOGICAL_CONTAMINATION';
public const QUALITY_PESTICIDES = 'PESTICIDES';
public const QUALITY_MEDICINES = 'MEDICINES';
public const QUALITY_PFA = 'PFA';
public const QUALITY_OXIDANTS = 'OXIDANTS';
public const QUALITY_BYPRODUCTS = 'BYPRODUCTS';
public const QUALITY_HYDROCARBONS = 'HYDROCARBONS';
public const QUALITY_SYNTHETIC_CHEMICALS = 'SYNTHETIC_CHEMICALS';
public const QUALITY_ORGANIC = 'ORGANIC';
public const QUALITY_RADIOACTIVITY = 'RADIOACTIVITY';
public const QUALITY_METALS = 'METALS';
public const QUALITY_SALTS = 'SALTS';
public const QUALITY_NITRATES_SULFATES_PHOSPHATES = 'NITRATES_SULFATES_PHOSPHATES';
public const QUALITY_MINERALIZATION = 'MINERALIZATION';
public const QUALITY_IRON_MANGANESE = 'IRON_MANGANESE';
/**
* @var string
*/
private $uuid;
/**
* @var string
*/
private $parameterCode;
/**
* @var string
*/
private $parameterName;
/**
* @var string
*/
private $parameterMetric;
/**
* @var float
*/
private $referenceMinValue;
/**
* @var float
*/
private $referenceValue;
/**
* @var float
*/
private $referenceMaxValue;
/**
* @var float
*/
private $limitMinValue;
/**
* @var float
*/
private $limitMaxValue;
/**
* @var string
*/
private $positivePresenceEffects;
/**
* @var string
*/
private $negativePresenceEffects;
/**
* @var string
*/
private $negativeAbsenceEffects;
/**
* @var string
*/
private $negativeExcessEffects;
/**
* @var string
*/
private $parameterDescription;
/**
* @var array
*/
private $relevantQualities;
/**
* @var string
*/
private $notes;
/**
* @var \DateTime
*/
private $createdAt;
public function __construct(
string $analyticalParameterId = null,
string $parameterCode,
string $parameterName,
string $parameterMetric,
float $referenceMinValue = null,
float $referenceValue = null,
float $referenceMaxValue = null,
float $limitMinValue = null,
float $limitMaxValue = null
) {
try {
$this->uuid = Uuid::fromString($analyticalParameterId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->parameterCode = $parameterCode;
$this->parameterName = $parameterName;
$this->parameterMetric = $parameterMetric;
$this->referenceMinValue = $referenceMinValue;
$this->referenceValue = $referenceValue;
$this->referenceMaxValue = $referenceMaxValue;
$this->limitMinValue = $limitMinValue;
$this->limitMaxValue = $limitMaxValue;
$this->relevantQualities = [];
$this->createdAt = new \DateTime();
}
public function updateAnalyticalParameter(
string $parameterName,
string $parameterMetric,
float $referenceMinValue = null,
float $referenceValue = null,
float $referenceMaxValue = null,
float $limitMinValue = null,
float $limitMaxValue = null
) {
$this->parameterName = $parameterName;
$this->parameterMetric = $parameterMetric;
$this->referenceMinValue = $referenceMinValue;
$this->referenceValue = $referenceValue;
$this->referenceMaxValue = $referenceMaxValue;
$this->limitMinValue = $limitMinValue;
$this->limitMaxValue = $limitMaxValue;
}
public function updateAnalyticalParameterDescriptions(
string $positivePresenceEffects = null,
string $negativePresenceEffects = null,
string $negativeAbsenceEffects = null,
string $negativeExcessEffects = null,
string $parameterDescription = null,
string $notes = null
) {
$this->positivePresenceEffects = $positivePresenceEffects;
$this->negativePresenceEffects = $negativePresenceEffects;
$this->negativeAbsenceEffects = $negativeAbsenceEffects;
$this->negativeExcessEffects = $negativeExcessEffects;
$this->parameterDescription = $parameterDescription;
$this->notes = $notes;
}
public function addRelevantQuality(string $relevantQuality): void
{
switch ($relevantQuality) {
case self::QUALITY_IMPROVE_PERCEPTION:
case self::QUALITY_BIOLOGICAL_CONTAMINATION:
case self::QUALITY_PESTICIDES:
case self::QUALITY_MEDICINES:
case self::QUALITY_PFA:
case self::QUALITY_OXIDANTS:
case self::QUALITY_BYPRODUCTS:
case self::QUALITY_HYDROCARBONS:
case self::QUALITY_SYNTHETIC_CHEMICALS:
case self::QUALITY_ORGANIC:
case self::QUALITY_RADIOACTIVITY:
case self::QUALITY_METALS:
case self::QUALITY_SALTS:
case self::QUALITY_NITRATES_SULFATES_PHOSPHATES:
case self::QUALITY_MINERALIZATION:
case self::QUALITY_IRON_MANGANESE:
if (!in_array($relevantQuality, $this->relevantQualities, true)) {
$this->relevantQualities[] = $relevantQuality;
}
break;
default:
throw new InvalidArgumentException("Invalid quality: $relevantQuality");
}
}
public function removeRelevantQuality(string $relevantQuality): void
{
$this->relevantQualities = array_filter(
$this->relevantQualities,
fn($quality) => $quality !== $relevantQuality
);
// Reindex the array to maintain numerical keys
$this->relevantQualities = array_values($this->relevantQualities);
}
public function cleanRelevantQuality(): void
{
$this->relevantQualities = [];
}
public function editNotes(string $notes = null): string
{
$this->notes = $notes;
return $this->notes;
}
public function editDescription(string $parameterDescription = null): string
{
$this->parameterDescription = $parameterDescription;
return $this->parameterDescription;
}
/**
* @return string
*/
public function id(): string
{
return $this->uuid;
}
/**
* @return string
*/
public function parameterCode(): string
{
return $this->parameterCode;
}
/**
* @return string
*/
public function parameterName(): string
{
return $this->parameterName;
}
/**
* @return string
*/
public function parameterMetric(): string
{
return $this->parameterMetric;
}
/**
* @return float
*/
public function referenceMinValue(): ?float
{
return $this->referenceMinValue;
}
/**
* @return float
*/
public function referenceValue(): ?float
{
return $this->referenceValue;
}
/**
* @return float
*/
public function referenceMaxValue(): ?float
{
return $this->referenceMaxValue;
}
/**
* @return float
*/
public function limitMinValue(): ?float
{
return $this->limitMinValue;
}
/**
* @return float
*/
public function limitMaxValue(): ?float
{
return $this->limitMaxValue;
}
/**
* @return array
*/
public function relevantQualities(): ?array
{
return $this->relevantQualities;
}
/**
* @return string
*/
public function positivePresenceEffects(): ?string
{
return $this->positivePresenceEffects;
}
/**
* @return string
*/
public function negativePresenceEffects(): ?string
{
return $this->negativePresenceEffects;
}
/**
* @return string
*/
public function negativeAbsenceEffects(): ?string
{
return $this->negativeAbsenceEffects;
}
/**
* @return string
*/
public function negativeExcessEffects(): ?string
{
return $this->negativeExcessEffects;
}
/**
* @return string
*/
public function parameterDescription(): ?string
{
return $this->parameterDescription;
}
/**
* @return string
*/
public function notes(): ?string
{
return $this->notes;
}
/**
* @return \DateTime
*/
public function createdAt(): \DateTime
{
return $this->createdAt;
}
/**
* @return bool
*/
public function equals(AnalyticalParameter $analyticalParameter)
{
return $this->id() === $analyticalParameter->id();
}
}