using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using EntityFrameworkCore.Projectables;
using Microsoft.EntityFrameworkCore;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("announcement")]
[Index(nameof(CreatedAt))]
public class Announcement
{
[Key]
[Column("id")]
[StringLength(32)]
public string Id { get; set; } = null!;
///
/// The created date of the Announcement.
///
[Column("createdAt")]
public DateTime CreatedAt { get; set; }
[Column("text")] [StringLength(8192)] public string Text { get; set; } = null!;
[Column("title")] [StringLength(256)] public string Title { get; set; } = null!;
[Column("imageUrl")]
[StringLength(1024)]
public string? ImageUrl { get; set; }
///
/// The updated date of the Announcement.
///
[Column("updatedAt")]
public DateTime? UpdatedAt { get; set; }
[Column("showPopup")] public bool ShowPopup { get; set; }
[Column("isGoodNews")] public bool IsGoodNews { get; set; }
[InverseProperty(nameof(AnnouncementRead.Announcement))]
public virtual ICollection AnnouncementReads { get; set; } = new List();
[NotMapped] [Projectable] public virtual IEnumerable ReadBy => AnnouncementReads.Select(p => p.User);
[Projectable]
public bool IsReadBy(User user) => ReadBy.Contains(user);
}