<?php
namespace JanusHercules\HighVolumeProcess\Domain\Entity;
use App\Utility\DatabaseIdGenerator;
use App\Utility\DateTimeUtility;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use JanusHercules\HighVolumeProcess\Domain\Enum\ProcessStatus;
use JanusHercules\HighVolumeProcess\Domain\Enum\ProcessType;
use ValueError;
#[ORM\Entity]
#[ORM\Table(name: 'high_volume_processes')]
#[ORM\Index(columns: ['process_status', 'finalization_started_at'], name: 'idx_process_status')]
#[ORM\Index(columns: ['process_type', 'process_status'], name: 'idx_process_type_status')]
class HighVolumeProcess
{
/**
* @throws Exception
*/
public function __construct(
ProcessType $processType,
string $processInfo = ''
) {
if (mb_strlen($processInfo) > 255) {
throw new ValueError('The processInfo cannot exceed 255 characters.');
}
$this->processType = $processType;
$this->processStatus = ProcessStatus::CREATED;
$this->createdAt = DateTimeUtility::createDateTimeUtc();
$this->processInfo = $processInfo;
}
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
#[ORM\Column(
type: Types::GUID,
unique: true
)]
private ?string $id = null;
public function getId(): ?string
{
return $this->id;
}
#[ORM\Column(
type: Types::STRING,
enumType: ProcessType::class
)]
private ProcessType $processType;
public function getProcessType(): ProcessType
{
return $this->processType;
}
#[ORM\Column(
type: Types::DATETIME_MUTABLE
)]
private DateTime $createdAt;
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: true
)]
private ?DateTime $lastUpdatedAt = null;
public function setLastUpdatedAt(DateTime $lastUpdatedAt): void
{
$this->lastUpdatedAt = $lastUpdatedAt;
}
public function getLastUpdatedAt(): ?DateTime
{
return $this->lastUpdatedAt;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: true
)]
private ?DateTime $finishedAt = null;
public function getFinishedAt(): ?DateTime
{
return $this->finishedAt;
}
public function setFinishedAt(?DateTime $finishedAt): void
{
$this->finishedAt = $finishedAt;
}
#[ORM\Column(
type: Types::STRING,
length: 255,
)]
private string $processInfo;
public function getProcessInfo(): string
{
return $this->processInfo;
}
#[ORM\Column(
type: Types::STRING,
enumType: ProcessStatus::class
)]
private ProcessStatus $processStatus;
public function getProcessStatus(): ProcessStatus
{
return $this->processStatus;
}
public function setProcessStatus(ProcessStatus $processStatus): void
{
$this->processStatus = $processStatus;
}
#[ORM\Column(
type : Types::TEXT,
nullable: true
)]
private ?string $errorMessage = null;
public function getErrorMessage(): ?string
{
return $this->errorMessage;
}
public function setErrorMessage(string $errorMessage): void
{
$this->errorMessage = mb_substr($errorMessage, 0, 1024);
}
#[ORM\Column(
type : Types::INTEGER,
nullable: false
)]
private int $numberOfItemsToProcess = 0;
public function getNumberOfItemsToProcess(): int
{
return $this->numberOfItemsToProcess;
}
public function setNumberOfItemsToProcess(
int $numberOfItemsToProcess
): void {
if ($numberOfItemsToProcess < 0) {
throw new ValueError('numberOfItemsToProcess must be greater than 0.');
}
$this->numberOfItemsToProcess = $numberOfItemsToProcess;
}
#[ORM\Column(
type : Types::INTEGER,
nullable: false
)]
private int $numberOfEnqueuedItems = 0;
public function getNumberOfEnqueuedItems(): int
{
return $this->numberOfEnqueuedItems;
}
#[ORM\Column(
type : Types::INTEGER,
nullable: false
)]
private int $numberOfSuccessfullyProcessedItems = 0;
public function getNumberOfSuccessfullyProcessedItems(): int
{
return $this->numberOfSuccessfullyProcessedItems;
}
#[ORM\Column(
type : Types::INTEGER,
nullable: false
)]
private int $numberOfUnsuccessfullyProcessedItems = 0;
public function getNumberOfUnsuccessfullyProcessedItems(): int
{
return $this->numberOfUnsuccessfullyProcessedItems;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: true
)]
private ?DateTime $finalizationStartedAt = null;
public function getFinalizationStartedAt(): ?DateTime
{
return $this->finalizationStartedAt;
}
#[ORM\Column(
type: Types::DATETIME_MUTABLE,
nullable: true
)]
private ?DateTime $markedForDeletionAfter = null;
public function getMarkedForDeletionAfter(): ?DateTime
{
return $this->markedForDeletionAfter;
}
public function setMarkedForDeletionAfter(?DateTime $markedForDeletionAfter): void
{
$this->markedForDeletionAfter = $markedForDeletionAfter;
}
}