Перевод на доменную архитектуру
This commit is contained in:
117
app/Application/Reports/DTO/GenerateReportInput.php
Normal file
117
app/Application/Reports/DTO/GenerateReportInput.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Application\Reports\DTO;
|
||||
|
||||
use App\Domain\Reports\Models\ReportContext;
|
||||
use App\Domain\Reports\Models\ReportSnapshot;
|
||||
use DateTimeImmutable;
|
||||
|
||||
final readonly class GenerateReportInput
|
||||
{
|
||||
/**
|
||||
* @param array<int|string, int|float|string|null> $metrics
|
||||
* @param array<int, array<string, mixed>> $observationPatients
|
||||
* @param array<int, array<string, mixed>> $unwantedEvents
|
||||
* @param array<string, mixed>|null $rawPayload
|
||||
*/
|
||||
public function __construct(
|
||||
public int $departmentId,
|
||||
public int $userId,
|
||||
public ?int $actorUserId,
|
||||
public DateTimeImmutable $periodStart,
|
||||
public DateTimeImmutable $periodEnd,
|
||||
public array $metrics = [],
|
||||
public array $observationPatients = [],
|
||||
public array $unwantedEvents = [],
|
||||
public ?int $reportId = null,
|
||||
public string $status = 'draft',
|
||||
public string $reportType = 'daily',
|
||||
public bool $autoFill = false,
|
||||
public ?array $rawPayload = null,
|
||||
public ?int $persistedReportId = null,
|
||||
public ?DateTimeImmutable $createdAt = null,
|
||||
public ?DateTimeImmutable $sentAt = null,
|
||||
) {}
|
||||
|
||||
public function toContext(): ReportContext
|
||||
{
|
||||
return new ReportContext(
|
||||
departmentId: $this->departmentId,
|
||||
userId: $this->userId,
|
||||
actorUserId: $this->actorUserId,
|
||||
periodStart: $this->periodStart,
|
||||
periodEnd: $this->periodEnd,
|
||||
reportType: $this->reportType,
|
||||
metadata: [
|
||||
'auto_fill' => $this->autoFill,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function toSnapshot(): ReportSnapshot
|
||||
{
|
||||
return new ReportSnapshot(
|
||||
departmentId: $this->departmentId,
|
||||
userId: $this->userId,
|
||||
actorUserId: $this->actorUserId,
|
||||
periodStart: $this->periodStart,
|
||||
periodEnd: $this->periodEnd,
|
||||
status: $this->status,
|
||||
autoFill: $this->autoFill,
|
||||
metrics: $this->metrics,
|
||||
observationPatients: $this->observationPatients,
|
||||
unwantedEvents: $this->unwantedEvents,
|
||||
reportId: $this->reportId,
|
||||
createdAt: $this->createdAt,
|
||||
sentAt: $this->sentAt,
|
||||
reportType: $this->reportType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $payload
|
||||
*/
|
||||
public function withRawPayload(array $payload): self
|
||||
{
|
||||
return new self(
|
||||
departmentId: $this->departmentId,
|
||||
userId: $this->userId,
|
||||
actorUserId: $this->actorUserId,
|
||||
periodStart: $this->periodStart,
|
||||
periodEnd: $this->periodEnd,
|
||||
metrics: $this->metrics,
|
||||
observationPatients: $this->observationPatients,
|
||||
unwantedEvents: $this->unwantedEvents,
|
||||
reportId: $this->reportId,
|
||||
status: $this->status,
|
||||
reportType: $this->reportType,
|
||||
autoFill: $this->autoFill,
|
||||
rawPayload: $payload,
|
||||
persistedReportId: $this->persistedReportId,
|
||||
createdAt: $this->createdAt,
|
||||
sentAt: $this->sentAt,
|
||||
);
|
||||
}
|
||||
|
||||
public function withPersistedReportId(int $reportId): self
|
||||
{
|
||||
return new self(
|
||||
departmentId: $this->departmentId,
|
||||
userId: $this->userId,
|
||||
actorUserId: $this->actorUserId,
|
||||
periodStart: $this->periodStart,
|
||||
periodEnd: $this->periodEnd,
|
||||
metrics: $this->metrics,
|
||||
observationPatients: $this->observationPatients,
|
||||
unwantedEvents: $this->unwantedEvents,
|
||||
reportId: $this->reportId,
|
||||
status: $this->status,
|
||||
reportType: $this->reportType,
|
||||
autoFill: $this->autoFill,
|
||||
rawPayload: $this->rawPayload,
|
||||
persistedReportId: $reportId,
|
||||
createdAt: $this->createdAt,
|
||||
sentAt: $this->sentAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user