using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("channel")]
[Index(nameof(UsersCount))]
[Index(nameof(NotesCount))]
[Index(nameof(LastNotedAt))]
[Index(nameof(CreatedAt))]
[Index(nameof(UserId))]
public class Channel
{
[Key]
[Column("id")]
[StringLength(32)]
public string Id { get; set; } = null!;
///
/// The created date of the Channel.
///
[Column("createdAt")]
public DateTime CreatedAt { get; set; }
[Column("lastNotedAt")] public DateTime? LastNotedAt { get; set; }
///
/// The owner ID.
///
[Column("userId")]
[StringLength(32)]
public string? UserId { get; set; }
///
/// The name of the Channel.
///
[Column("name")]
[StringLength(128)]
public string Name { get; set; } = null!;
///
/// The description of the Channel.
///
[Column("description")]
[StringLength(2048)]
public string? Description { get; set; }
///
/// The ID of banner Channel.
///
[Column("bannerId")]
[StringLength(32)]
public string? BannerId { get; set; }
///
/// The count of notes.
///
[Column("notesCount")]
public int NotesCount { get; set; }
///
/// The count of users.
///
[Column("usersCount")]
public int UsersCount { get; set; }
[ForeignKey(nameof(BannerId))]
[InverseProperty(nameof(DriveFile.Channels))]
public virtual DriveFile? Banner { get; set; }
[InverseProperty(nameof(ChannelFollowing.Followee))]
public virtual ICollection ChannelFollowings { get; set; } = new List();
[InverseProperty(nameof(ChannelNotePin.Channel))]
public virtual ICollection ChannelNotePins { get; set; } = new List();
[InverseProperty(nameof(Note.Channel))]
public virtual ICollection Notes { get; set; } = new List();
[ForeignKey(nameof(UserId))]
[InverseProperty(nameof(Tables.User.Channels))]
public virtual User? User { get; set; }
private class EntityTypeConfiguration : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder entity)
{
entity.Property(e => e.BannerId).HasComment("The ID of banner Channel.");
entity.Property(e => e.CreatedAt).HasComment("The created date of the Channel.");
entity.Property(e => e.Description).HasComment("The description of the Channel.");
entity.Property(e => e.Name).HasComment("The name of the Channel.");
entity.Property(e => e.NotesCount)
.HasDefaultValue(0)
.HasComment("The count of notes.");
entity.Property(e => e.UserId).HasComment("The owner ID.");
entity.Property(e => e.UsersCount)
.HasDefaultValue(0)
.HasComment("The count of users.");
entity.HasOne(d => d.Banner)
.WithMany(p => p.Channels)
.OnDelete(DeleteBehavior.SetNull);
entity.HasOne(d => d.User)
.WithMany(p => p.Channels)
.OnDelete(DeleteBehavior.SetNull);
}
}
}