Перевод на доменную архитектуру

This commit is contained in:
brusnitsyn
2026-04-26 23:37:50 +09:00
parent 75ca01ffd8
commit f107ebd167
70 changed files with 4656 additions and 2070 deletions

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Domain\Reports\Models;
use App\Domain\Reports\ValueObjects\MetrikaConfig;
use DateTimeImmutable;
use InvalidArgumentException;
final readonly class ReportSnapshot
{
/**
* @param array<int|string, int|float|string|null> $metrics
* @param array<int, array<string, mixed>> $observationPatients
* @param array<int, array<string, mixed>> $unwantedEvents
*/
public function __construct(
public int $departmentId,
public int $userId,
public ?int $actorUserId,
public DateTimeImmutable $periodStart,
public DateTimeImmutable $periodEnd,
public string $status = 'draft',
public bool $autoFill = false,
public array $metrics = [],
public array $observationPatients = [],
public array $unwantedEvents = [],
public ?int $reportId = null,
public ?DateTimeImmutable $createdAt = null,
public ?DateTimeImmutable $sentAt = null,
public string $reportType = 'daily',
) {
if ($this->departmentId <= 0) {
throw new InvalidArgumentException('departmentId must be positive.');
}
if ($this->userId <= 0) {
throw new InvalidArgumentException('userId must be positive.');
}
if ($this->periodEnd < $this->periodStart) {
throw new InvalidArgumentException('periodEnd must not be earlier than periodStart.');
}
}
/**
* @return array<int, int|float|string|null>
*/
public function normalizedMetrics(): array
{
return MetrikaConfig::normalizeMetrics($this->metrics);
}
/**
* @return array<string, int|float|string|null>
*/
public function payloadMetrics(): array
{
return MetrikaConfig::toPayloadMetrics($this->normalizedMetrics());
}
/**
* @return array<string, mixed>
*/
public function toComparableArray(): array
{
$observationPatients = $this->observationPatients;
$unwantedEvents = $this->unwantedEvents;
sort($observationPatients);
sort($unwantedEvents);
return [
'department_id' => $this->departmentId,
'user_id' => $this->userId,
'actor_user_id' => $this->actorUserId,
'period_start' => $this->periodStart->format('Y-m-d H:i:s'),
'period_end' => $this->periodEnd->format('Y-m-d H:i:s'),
'status' => $this->status,
'auto_fill' => $this->autoFill,
'metrics' => $this->normalizedMetrics(),
'observation_patients' => $observationPatients,
'unwanted_events' => $unwantedEvents,
];
}
}