<?php
namespace App\Entity;
use App\Utility\GuidUtility;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use ReflectionClass;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="email_delivery_notifications",
* indexes={
*
* @ORM\Index(name="users_id_mail_sent_at_idx", columns={"users_id", "mail_sent_at"}),
* @ORM\Index(name="email_mail_sent_at_idx", columns={"email", "mail_sent_at"}),
* @ORM\Index(name="notification_type_mail_sent_at_idx", columns={"notification_type", "mail_sent_at"}),
* @ORM\Index(name="mail_sent_at_idx", columns={"mail_sent_at"})
* }
* )
*/
class EmailDeliveryNotification
{
public const NOTIFICATION_TYPE_DELIVERY = 0;
public const NOTIFICATION_TYPE_BOUNCE = 1;
public const NOTIFICATION_TYPE_COMPLAINT = 2;
/**
* @var string
*
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
*
* @ORM\Column(name="id", type="guid")
*
* @ORM\Id
*/
protected $id;
public function setId(string $id): void
{
GuidUtility::validOrThrow($id);
$this->id = $id;
}
public function getId()
{
return $this->id;
}
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="emailDeliveryNotifications")
*
* @ORM\JoinColumn(name="users_id", onDelete="CASCADE", nullable=true)
*/
protected $user;
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user = null): void
{
$this->user = $user;
}
/**
* @var int
*
* @ORM\Column(name="notification_type", type="smallint", nullable=false)
*/
protected $notificationType;
/**
* @throws Exception
*/
public function setNotificationType(int $notificationType): void
{
$refl = new ReflectionClass(EmailDeliveryNotification::class);
$constants = $refl->getConstants();
$found = false;
foreach ($constants as $constantName => $constantValue) {
if (substr($constantName, 0, 18) === 'NOTIFICATION_TYPE_' && $constantValue === $notificationType) {
$found = true;
}
}
if (!$found) {
throw new Exception('Value ' . $notificationType . ' not allowed for notificationType.');
}
$this->notificationType = $notificationType;
}
public function getNotificationType(): int
{
return $this->notificationType;
}
/**
* @var int
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*/
protected $email;
/**
* @throws Exception
*/
public function setEmail(string $email): void
{
$this->email = $email;
}
public function getEmail(): string
{
return $this->email;
}
/**
* @ORM\Column(name="smtp_message", type="string", length=8192, nullable=false)
*/
protected $smtpMessage;
/**
* @throws Exception
*/
public function setSmtpMessage(string $smtpMessage): void
{
$this->smtpMessage = $smtpMessage;
}
public function getSmtpMessage(): string
{
return $this->smtpMessage;
}
/**
* @ORM\Column(name="mail_message_id", type="string", length=2014, nullable=false)
*/
protected $mailMessageId;
/**
* @throws Exception
*/
public function setMailMessageId(string $mailMessageId): void
{
$this->mailMessageId = $mailMessageId;
}
public function getMailMessageId(): string
{
return $this->mailMessageId;
}
/**
* @var DateTime
*
* @ORM\Column(name="notification_received_at", type="datetime", nullable=false)
*/
protected $notificationReceivedAt;
public function setNotificationReceivedAt(DateTime $notificationReceivedAt): void
{
$this->notificationReceivedAt = $notificationReceivedAt;
}
public function getNotificationReceivedAt(): DateTime
{
return $this->notificationReceivedAt;
}
/**
* @var DateTime
*
* @ORM\Column(name="mail_sent_at", type="datetime", nullable=false)
*/
protected $mailSentAt;
public function setMailSentAt(DateTime $mailSentAt): void
{
$this->mailSentAt = $mailSentAt;
}
public function getMailSentAt(): DateTime
{
return $this->mailSentAt;
}
/**
* @var DateTime
*
* @ORM\Column(name="delivery_event_occured_at", type="datetime", nullable=false)
*/
protected $deliveryEventOccuredAt;
public function setDeliveryEventOccuredAt(DateTime $deliveryEventOccuredAt): void
{
$this->deliveryEventOccuredAt = $deliveryEventOccuredAt;
}
public function getDeliveryEventOccuredAt(): DateTime
{
return $this->deliveryEventOccuredAt;
}
/**
* @ORM\Column(name="subject", type="text", length=4096, nullable=true)
*/
protected $subject;
/**
* @throws Exception
*/
public function setSubject(string $subject)
{
$this->subject = $subject;
}
public function getSubject()
{
return $this->subject;
}
/**
* @ORM\Column(name="raw_notification_message", type="text", length=8192, nullable=false)
*/
protected $rawNotificationMessage;
/**
* @throws Exception
*/
public function setRawNotificationMessage(string $rawNotificationMessage)
{
if (is_null(json_decode($rawNotificationMessage))) {
throw new Exception('rawNotificationMessage must be valid JSON, but ' . $rawNotificationMessage . ' is not.');
}
$this->rawNotificationMessage = $rawNotificationMessage;
}
public function getRawNotificationMessage()
{
return $this->rawNotificationMessage;
}
}