<?php
namespace App\Entity\Email;
use App\Entity\Email\EmailMessage;
use App\Enum\EmailMessageStatusEnum;
use App\Repository\Email\EmailMessageStatusRepository;
use DateTime;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="vulco_email_message_status")
* @ORM\Entity(repositoryClass=EmailMessageStatusRepository::class)
*
* @see https://developers.brevo.com/docs/transactional-webhooks
* @see https://developers.brevo.com/reference/gettransacemailcontent
*/
class EmailMessageStatus
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected int $id;
/**
* @ORM\ManyToOne(targetEntity="EmailMessage", inversedBy="statuses")
*/
private EmailMessage $emailMessage;
/**
* @ORM\Column(type="string", length=255, nullable=false, options={"default": "unknown"})
*/
private string $status = EmailMessageStatusEnum::UNKNOWN;
/**
* @ORM\Column(type="datetime")
*/
private DateTimeInterface $date;
/**
* @ORM\Column(type="string", length=1023, nullable=true)
*/
private ?string $link = null; // URL accessed by recipient
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $deviceUsed = null; // Details about the device from which the action originated (DESKTOP, MOBILE, ...)
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $reason = null; // The reason the message has been deferred, soft_bounced or hard_bounce
public function __construct(
string $status = EmailMessageStatusEnum::UNKNOWN,
DateTimeInterface $date = new DateTime())
{
$this->status = $status;
$this->date = $date;
}
public function getId(): int
{
return $this->id;
}
public function getEmailMessage(): EmailMessage
{
return $this->emailMessage;
}
public function setEmailMessage(EmailMessage $emailMessage): self
{
$this->emailMessage = $emailMessage;
return $this;
}
public function getStatus(): string
{
return $this->status;
}
public function getStatusAsTranslationKey(): string
{
if (array_key_exists($this->status, EmailMessageStatusEnum::getTranslations())) {
return EmailMessageStatusEnum::getTranslations()[$this->status];
}
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getDate(): DateTimeInterface
{
return $this->date;
}
public function setDate(DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getLink(): ?string
{
return $this->link;
}
public function setLink(?string $link): EmailMessageStatus
{
$this->link = $link;
return $this;
}
public function getDeviceUsed(): ?string
{
return $this->deviceUsed;
}
public function setDeviceUsed(?string $deviceUsed): self
{
$this->deviceUsed = $deviceUsed;
return $this;
}
public function getReason(): ?string
{
return $this->reason;
}
public function setReason(?string $reason): self
{
$this->reason = $reason;
return $this;
}
public function isUnknown(): bool
{
if ($this->isSent()
|| $this->isClicked()
|| $this->isDeferred()
|| $this->isDelivered()
|| $this->isSoftBounced()
|| $this->isHardBounced()
|| $this->isSpam()
|| $this->isOpened()
|| $this->isInvalidEmail()
|| $this->isBlocked()
|| $this->isError()
) {
return false;
}
return true;
}
public function isSent(): bool
{
if (EmailMessageStatusEnum::SENT === $this->getStatus()) {
return true;
}
return false;
}
public function isClicked(): bool
{
if (EmailMessageStatusEnum::CLICKED === $this->getStatus()) {
return true;
}
return false;
}
public function isDeferred(): bool
{
if (EmailMessageStatusEnum::DEFERRED === $this->getStatus()) {
return true;
}
return false;
}
public function isDelivered(): bool
{
if (EmailMessageStatusEnum::DELIVERED === $this->getStatus()) {
return true;
}
return false;
}
public function isSoftBounced(): bool
{
if (EmailMessageStatusEnum::SOFT_BOUNCED === $this->getStatus()) {
return true;
}
return false;
}
public function isHardBounced(): bool
{
if (EmailMessageStatusEnum::HARD_BOUNCED === $this->getStatus()) {
return true;
}
return false;
}
public function isSpam(): bool
{
if (EmailMessageStatusEnum::SPAM === $this->getStatus()) {
return true;
}
return false;
}
public function isOpened(): bool
{
if (EmailMessageStatusEnum::OPENED === $this->getStatus()) {
return true;
}
return false;
}
public function isInvalidEmail(): bool
{
if (EmailMessageStatusEnum::INVALID_EMAIL === $this->getStatus()) {
return true;
}
return false;
}
public function isBlocked(): bool
{
if (EmailMessageStatusEnum::BLOCKED === $this->getStatus()) {
return true;
}
return false;
}
public function isError(): bool
{
if (EmailMessageStatusEnum::ERROR === $this->getStatus()) {
return true;
}
return false;
}
}