<?php
namespace App\Entity;
use App\Repository\NotificationRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: NotificationRepository::class)]
class Notification
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'notifications')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user = null;
#[ORM\Column(length: 50)]
private ?string $type = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $content = null;
#[ORM\Column]
private ?bool $isRead = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(type: 'json', nullable: true)]
private ?array $data = null;
public function __construct()
{
$this->isRead = false;
$this->createdAt = new \DateTimeImmutable();
}
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 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 isIsRead(): ?bool
{
return $this->isRead;
}
public function setIsRead(bool $isRead): static
{
$this->isRead = $isRead;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getData(): ?array
{
return $this->data;
}
public function setData(?array $data): static
{
$this->data = $data;
return $this;
}
/**
* Mark the notification as read
*/
public function markAsRead(): static
{
$this->isRead = true;
return $this;
}
/**
* Check if the notification is for a submission
*/
public function isSubmissionNotification(): bool
{
return in_array($this->type, ['submission_approved', 'submission_rejected']);
}
/**
* Check if the notification is for a team
*/
public function isTeamNotification(): bool
{
return in_array($this->type, ['team_joined', 'team_left', 'team_role_changed']);
}
/**
* Check if the notification is for a season
*/
public function isSeasonNotification(): bool
{
return in_array($this->type, ['season_started', 'season_ended']);
}
}