<?php
namespace App\Entity;
use App\Repository\NotificationRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: NotificationRepository::class)]
class Notification
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(length: 255)]
private ?string $message = null;
#[ORM\Column(length: 255)]
private ?string $type = null;
#[ORM\Column]
private ?bool $isRead = null;
#[ORM\Column]
private ?bool $isArchived = null;
#[ORM\Column]
private ?bool $isDeleted = null;
#[ORM\Column]
private ?int $priority = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $readAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $archivedAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $deletedAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $expiresAt = null;
#[ORM\ManyToOne(inversedBy: 'notifications')]
private ?User $user = null;
#[ORM\ManyToOne(inversedBy: 'notifications')]
private ?Shop $shop = null;
// Types de notifications
public const TYPE_ORDER = 'order';
public const TYPE_DELIVERY = 'delivery';
public const TYPE_SHOP_FOLLOW = 'shop_follow';
public const TYPE_PRODUCT_REVIEW = 'product_review';
public const TYPE_SHOP_REVIEW = 'shop_review';
public const TYPE_DROPSHIP_SALE = 'dropship_sale';
public const TYPE_SYSTEM = 'system';
public const TYPE_PROMOTION = 'promotion';
// Priorités
public const PRIORITY_LOW = 1;
public const PRIORITY_MEDIUM = 2;
public const PRIORITY_HIGH = 3;
public const PRIORITY_URGENT = 4;
public function __construct()
{
$this->isRead = false;
$this->isArchived = false;
$this->isDeleted = false;
$this->priority = self::PRIORITY_MEDIUM;
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setMessage(string $message): static
{
$this->message = $message;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
public function isIsRead(): ?bool
{
return $this->isRead;
}
public function setIsRead(bool $isRead): static
{
$this->isRead = $isRead;
return $this;
}
public function isIsArchived(): ?bool
{
return $this->isArchived;
}
public function setIsArchived(bool $isArchived): static
{
$this->isArchived = $isArchived;
return $this;
}
public function getPriority(): ?int
{
return $this->priority;
}
public function setPriority(int $priority): static
{
$this->priority = $priority;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getReadAt(): ?\DateTimeImmutable
{
return $this->readAt;
}
public function setReadAt(?\DateTimeImmutable $readAt): static
{
$this->readAt = $readAt;
return $this;
}
public function getExpiresAt(): ?\DateTimeImmutable
{
return $this->expiresAt;
}
public function setExpiresAt(?\DateTimeImmutable $expiresAt): static
{
$this->expiresAt = $expiresAt;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): static
{
$this->user = $user;
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
public function markAsRead(): static
{
$this->isRead = true;
$this->readAt = new \DateTimeImmutable();
return $this;
}
public function markAsUnread(): static
{
$this->isRead = false;
$this->readAt = null;
return $this;
}
public function archive(): static
{
$this->isArchived = true;
$this->archivedAt = new \DateTimeImmutable();
return $this;
}
public function unarchive(): static
{
$this->isArchived = false;
$this->archivedAt = null;
return $this;
}
public function softDelete(): static
{
$this->isDeleted = true;
$this->deletedAt = new \DateTimeImmutable();
return $this;
}
public function restore(): static
{
$this->isDeleted = false;
$this->deletedAt = null;
return $this;
}
public function isIsDeleted(): ?bool
{
return $this->isDeleted;
}
public function setIsDeleted(bool $isDeleted): static
{
$this->isDeleted = $isDeleted;
return $this;
}
public function getArchivedAt(): ?\DateTimeImmutable
{
return $this->archivedAt;
}
public function setArchivedAt(?\DateTimeImmutable $archivedAt): static
{
$this->archivedAt = $archivedAt;
return $this;
}
public function getDeletedAt(): ?\DateTimeImmutable
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeImmutable $deletedAt): static
{
$this->deletedAt = $deletedAt;
return $this;
}
public function isExpired(): bool
{
return $this->expiresAt && $this->expiresAt < new \DateTimeImmutable();
}
public function getTypeIcon(): string
{
return match($this->type) {
self::TYPE_ORDER => 'lnr-shopping-cart',
self::TYPE_DELIVERY => 'lnr-truck',
self::TYPE_SHOP_FOLLOW => 'lnr-heart',
self::TYPE_PRODUCT_REVIEW => 'lnr-star',
self::TYPE_SHOP_REVIEW => 'lnr-star',
self::TYPE_DROPSHIP_SALE => 'lnr-link',
self::TYPE_SYSTEM => 'lnr-cog',
self::TYPE_PROMOTION => 'lnr-gift',
default => 'lnr-bell'
};
}
public function getPriorityClass(): string
{
return match($this->priority) {
self::PRIORITY_LOW => 'text-muted',
self::PRIORITY_MEDIUM => 'text-primary',
self::PRIORITY_HIGH => 'text-warning',
self::PRIORITY_URGENT => 'text-danger',
default => 'text-primary'
};
}
}