<?php
namespace JanusHercules\GohiringIntegration\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\GohiringIntegration\Domain\Enum\GohiringPositionEventSource;
use JanusHercules\GohiringIntegration\Domain\Enum\GohiringPositionEventType;
#[ORM\Entity]
#[ORM\Table(name: 'gi_gohiring_position_events')]
class GohiringPositionEvent
{
/**
* @throws Exception
*/
public function __construct(
string $positionId,
GohiringPositionEventType $eventType,
?DateTime $expiresAtReported = null,
bool $isSuccess = true,
string $info = '',
?DateTime $occuredAt = null,
GohiringPositionEventSource $source = GohiringPositionEventSource::LIVE,
) {
$this->positionId = $positionId;
$this->occuredAt = is_null($occuredAt) ? DateTimeUtility::createDateTimeUtc() : $occuredAt;
$this->eventType = $eventType;
$this->expiresAtReported = $expiresAtReported;
$this->isSuccess = $isSuccess;
$this->info = $info;
$this->source = $source;
}
#[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::GUID,
unique: false
)]
private readonly string $positionId;
public function getPositionId(): string
{
return $this->positionId;
}
#[ORM\Column(
type : Types::STRING,
enumType: GohiringPositionEventType::class
)]
private readonly GohiringPositionEventType $eventType;
public function getEventType(): GohiringPositionEventType
{
return $this->eventType;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: false
)]
private readonly DateTime $occuredAt;
public function getOccuredAt(): DateTime
{
return $this->occuredAt;
}
#[ORM\Column(
type : Types::DATETIME_MUTABLE,
nullable: true
)]
private ?DateTime $expiresAtReported;
public function getExpiresAtReported(): ?DateTime
{
return $this->expiresAtReported;
}
#[ORM\Column(
type : Types::BOOLEAN,
nullable: false
)]
private bool $isSuccess;
public function isSuccess(): bool
{
return $this->isSuccess;
}
#[ORM\Column(
type : Types::TEXT,
nullable: false
)]
private string $info;
public function getInfo(): string
{
return $this->info;
}
#[ORM\Column(
type : Types::STRING,
enumType: GohiringPositionEventSource::class
)]
private readonly GohiringPositionEventSource $source;
public function getSource(): GohiringPositionEventSource
{
return $this->source;
}
}