<?php
namespace App\Entity;
use App\Repository\ChatMessageRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups; // Add this use statement
#[ORM\Entity(repositoryClass: ChatMessageRepository::class)]
class ChatMessage
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(["chat_message"])]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'chatMessages')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(["chat_message"])] // User needs to be serializable with 'chat_message' group too
private ?User $user = null;
#[ORM\ManyToOne(inversedBy: 'chatMessages')]
#[ORM\JoinColumn(nullable: true)]
#[Groups(["chat_message"])] // Team needs to be serializable with 'chat_message' group too
private ?Team $team = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: true)]
#[Groups(["chat_message"])] // Season needs to be serializable with 'chat_message' group too
private ?Season $season = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: true)]
#[Groups(["chat_message"])] // Recipient (User) needs to be serializable
private ?User $recipient = null;
#[ORM\Column(length: 20)]
#[Groups(["chat_message"])]
private string $type = 'team'; // Options: 'team', 'season', 'direct'
#[ORM\Column(type: Types::TEXT)]
#[Groups(["chat_message"])]
private ?string $content = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(["chat_message"])]
private ?string $attachmentUrl = null;
#[ORM\Column]
#[Groups(["chat_message"])]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column]
#[Groups(["chat_message"])]
private ?bool $isRead = null;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->isRead = false;
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): static
{
$this->user = $user;
return $this;
}
public function getTeam(): ?Team
{
return $this->team;
}
public function setTeam(?Team $team): static
{
$this->team = $team;
return $this;
}
public function getSeason(): ?Season
{
return $this->season;
}
public function setSeason(?Season $season): static
{
$this->season = $season;
return $this;
}
public function getRecipient(): ?User
{
return $this->recipient;
}
public function setRecipient(?User $recipient): static
{
$this->recipient = $recipient;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): static
{
$this->content = $content;
return $this;
}
public function getAttachmentUrl(): ?string
{
return $this->attachmentUrl;
}
public function setAttachmentUrl(?string $attachmentUrl): static
{
$this->attachmentUrl = $attachmentUrl;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function isIsRead(): ?bool
{
return $this->isRead;
}
public function setIsRead(bool $isRead): static
{
$this->isRead = $isRead;
return $this;
}
/**
* Mark the message as read
*/
public function markAsRead(): static
{
$this->isRead = true;
return $this;
}
/**
* Check if the message has an attachment
*/
public function hasAttachment(): bool
{
return $this->attachmentUrl !== null;
}
}