<?php
namespace Products\NotificationsBundle\Entity\ContactAttempts;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Products\NotificationsBundle\Entity\AbstractContactAttempt;
use Products\NotificationsBundle\Entity\Recipients\EmailRecipient;
/**
* Class EmailContactAttempt
* @package Products\NotificationsBundle\Entity\ContactAttempts
*
* @method EmailRecipient getRecipient()
*
* @ORM\Entity(
* repositoryClass = "Products\NotificationsBundle\Doctrine\Repository\ContactAttempts\EmailContactAttemptRepository",
* )
*/
class EmailContactAttempt extends AbstractTransactionalContactAttempt
{
const DISCR = 'email';
/**
* @see https://sendgrid.com/docs/for-developers/tracking-events/event/
*/
const STATUSES = [
...self::PENDING_STATUSES,
...self::SUCCESSFUL_STATUSES,
...self::FAILED_STATUSES,
];
const PENDING_STATUSES = [
...AbstractContactAttempt::PENDING_STATUSES,
'email.processed',
'email.deferred',
];
const SUCCESSFUL_STATUSES = [
...AbstractContactAttempt::SUCCESSFUL_STATUSES,
'email.delivered',
];
const FAILED_STATUSES = [
...AbstractContactAttempt::FAILED_STATUSES,
'email.dropped',
'email.bounce',
];
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $reason = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $type = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $code = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $response = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $attempt = null;
/**
* @var DateTime|null
*
* @ORM\Column(
* type = "datetime",
* nullable = true,
* )
*/
protected ?DateTime $openedAt = null;
/**
* @var DateTime|null
*
* @ORM\Column(
* type = "datetime",
* nullable = true,
* )
*/
protected ?DateTime $spammedAt = null;
/**
* @return string|null
*/
public function getReason(): ?string
{
return $this->reason;
}
/**
* @param string $reason
* @return $this
*/
public function setReason(string $reason): self
{
$this->reason = $reason;
return $this;
}
/**
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @param string $type
* @return $this
*/
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
/**
* @return string|null
*/
public function getCode(): ?string
{
return $this->code;
}
/**
* @param string $code
* @return $this
*/
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
/**
* @return string|null
*/
public function getResponse(): ?string
{
return $this->response;
}
/**
* @param string $response
* @return $this
*/
public function setResponse(string $response): self
{
$this->response = $response;
return $this;
}
/**
* @return string|null
*/
public function getAttempt(): ?string
{
return $this->attempt;
}
/**
* @param string $attempt
* @return $this
*/
public function setAttempt(string $attempt): self
{
$this->attempt = $attempt;
return $this;
}
/**
* {@inheritDoc}
*/
public function getExtras(): array
{
return [
'opened' => $this->getOpenedAt() ? $this->getOpenedAt()->format('Y-m-d h:i:sA') : null,
'spammed' => $this->getSpammedAt() ? $this->getSpammedAt()->format('Y-m-d h:i:sA') : null,
'response' => $this->getResponse(),
'code' => $this->getCode(),
'type' => $this->getType(),
'reason' => $this->getReason(),
'attempt' => $this->getAttempt(),
];
}
/**
* @return DateTime|null
*/
public function getOpenedAt(): ?DateTime
{
return $this->openedAt;
}
/**
* @param DateTime|null $openedAt
* @return self
*/
public function setOpenedAt(?DateTime $openedAt): self
{
$this->openedAt = $openedAt;
return $this;
}
/**
* @return DateTime|null
*/
public function getSpammedAt(): ?DateTime
{
return $this->spammedAt;
}
/**
* @param DateTime|null $spammedAt
* @return self
*/
public function setSpammedAt(?DateTime $spammedAt): self
{
$this->spammedAt = $spammedAt;
return $this;
}
}