<?php
namespace App\Entity;
use App\Repository\EmailMessageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EmailMessageRepository::class)]
#[ORM\Table(name: 'email_messages')]
class EmailMessage extends BaseEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: Sales::class, inversedBy: 'emailMessages')]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Sales $sale = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?User $sentBy = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $senderEmail = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $senderName = null;
#[ORM\Column(length: 255)]
private string $subject;
#[ORM\Column(type: 'text')]
private string $body;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $sentAt;
#[ORM\Column(length: 64, unique: true)]
private string $messageToken;
#[ORM\Column(length: 255, nullable: true)]
private ?string $externalMessageId = null;
/**
* @var Collection<int, EmailRecipient>
*/
#[ORM\OneToMany(mappedBy: 'emailMessage', targetEntity: EmailRecipient::class, cascade: ['persist'], orphanRemoval: true)]
private Collection $recipients;
public function __construct()
{
$this->recipients = new ArrayCollection();
$this->sentAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getSale(): ?Sales
{
return $this->sale;
}
public function setSale(?Sales $sale): self
{
$this->sale = $sale;
return $this;
}
public function getSentBy(): ?User
{
return $this->sentBy;
}
public function setSentBy(?User $sentBy): self
{
$this->sentBy = $sentBy;
return $this;
}
public function getSenderEmail(): ?string
{
return $this->senderEmail;
}
public function setSenderEmail(?string $senderEmail): self
{
$this->senderEmail = $senderEmail;
return $this;
}
public function getSenderName(): ?string
{
return $this->senderName;
}
public function setSenderName(?string $senderName): self
{
$this->senderName = $senderName;
return $this;
}
public function getSubject(): string
{
return $this->subject;
}
public function setSubject(string $subject): self
{
$this->subject = $subject;
return $this;
}
public function getBody(): string
{
return $this->body;
}
public function setBody(string $body): self
{
$this->body = $body;
return $this;
}
public function getSentAt(): \DateTimeImmutable
{
return $this->sentAt;
}
public function setSentAt(\DateTimeImmutable $sentAt): self
{
$this->sentAt = $sentAt;
return $this;
}
public function getMessageToken(): string
{
return $this->messageToken;
}
public function setMessageToken(string $messageToken): self
{
$this->messageToken = $messageToken;
return $this;
}
public function getExternalMessageId(): ?string
{
return $this->externalMessageId;
}
public function setExternalMessageId(?string $externalMessageId): self
{
$this->externalMessageId = $externalMessageId;
return $this;
}
/**
* @return Collection<int, EmailRecipient>
*/
public function getRecipients(): Collection
{
return $this->recipients;
}
public function addRecipient(EmailRecipient $recipient): self
{
if (!$this->recipients->contains($recipient)) {
$this->recipients->add($recipient);
$recipient->setEmailMessage($this);
}
return $this;
}
public function removeRecipient(EmailRecipient $recipient): self
{
if ($this->recipients->removeElement($recipient)) {
if ($recipient->getEmailMessage() === $this) {
$recipient->setEmailMessage(null);
}
}
return $this;
}
}