<?php
namespace App\Entity;
use App\Enum\MessageType;
use App\Enum\UpdateType;
use App\Repository\UpdateRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: UpdateRepository::class)]
#[ORM\Table(name: 'TicketUpdate')]
#[ORM\Index(columns: ['updateType'], name: 'ticket_update_idx_update_type')]
#[ORM\Index(columns: ['messageType'], name: 'ticket_update_idx_message_type')]
class Update
{
public function __construct(
#[ORM\Column(type:"string")]
private string $updateType,
#[ORM\Column(type:"string")]
private string $messageType,
#[ORM\Id]
#[ORM\Column(type:"string", length:36)]
private ?string $id = null,
#[ORM\ManyToOne(inversedBy: 'updates')]
#[ORM\JoinColumn(name: "ticketId", referencedColumnName: "id", nullable: false)]
private ?Ticket $ticket = null,
#[ORM\Column(type:"text", nullable: true)]
private ?string $description = null,
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?DateTimeImmutable $createdAt = null,
#[ORM\OneToMany(
mappedBy: 'update',
targetEntity: UpdateAttachment::class,
cascade: ['persist'],
orphanRemoval: true
)]
private ?Collection $attachments = null,
) {
$this->id = is_null($this->id) ? Uuid::v4()->toRfc4122() : $this->id;
$this->attachments = is_null($this->attachments) ? new ArrayCollection() : $this->attachments;
$this->createdAt = is_null($this->createdAt) ? new DateTimeImmutable('now') : $this->createdAt;
}
public function getId(): ?string
{
return $this->id;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getTicket(): ?Ticket
{
return $this->ticket;
}
public function setTicket(?Ticket $ticket): self
{
$this->ticket = $ticket;
return $this;
}
public function getUpdateType(): string
{
return $this->updateType;
}
public function setUpdateType(UpdateType $updateType): void
{
$this->updateType = $updateType->value;
}
public function getMessageType(): string
{
return $this->messageType;
}
public function setMessageType(MessageType $messageType): self
{
$this->messageType = $messageType->value;
return $this;
}
/**
* @return Collection|null
*/
public function getAttachments(): ?Collection
{
return $this->attachments;
}
public function addAttachment(UpdateAttachment $attachment): void
{
if ($this->attachments && !$this->attachments->contains($attachment)) {
$this->attachments->add($attachment);
}
}
public function removeAttachment(UpdateAttachment $attachment): void
{
if ($this->attachments && $this->attachments->contains($attachment)) {
$this->attachments->removeElement($attachment);
}
}
}