using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("user_group_invitation")]
[Index(nameof(UserGroupId))]
[Index(nameof(UserId))]
[Index(nameof(UserId), nameof(UserGroupId), IsUnique = true)]
public class UserGroupInvitation
{
[Key]
[Column("id")]
[StringLength(32)]
public string Id { get; set; } = null!;
///
/// The created date of the UserGroupInvitation.
///
[Column("createdAt")]
public DateTime CreatedAt { get; set; }
///
/// The user ID.
///
[Column("userId")]
[StringLength(32)]
public string UserId { get; set; } = null!;
///
/// The group ID.
///
[Column("userGroupId")]
[StringLength(32)]
public string UserGroupId { get; set; } = null!;
[InverseProperty(nameof(Notification.UserGroupInvitation))]
public virtual ICollection Notifications { get; set; } = new List();
[ForeignKey(nameof(UserId))]
[InverseProperty(nameof(Tables.User.UserGroupInvitations))]
public virtual User User { get; set; } = null!;
[ForeignKey(nameof(UserGroupId))]
[InverseProperty(nameof(Tables.UserGroup.UserGroupInvitations))]
public virtual UserGroup UserGroup { get; set; } = null!;
private class EntityTypeConfiguration : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder entity)
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the UserGroupInvitation.");
entity.Property(e => e.UserGroupId).HasComment("The group ID.");
entity.Property(e => e.UserId).HasComment("The user ID.");
entity.HasOne(d => d.UserGroup)
.WithMany(p => p.UserGroupInvitations)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User)
.WithMany(p => p.UserGroupInvitations)
.OnDelete(DeleteBehavior.Cascade);
}
}
}