using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Novelly.Api.Agent; using Novelly.Api.Chapters; using Novelly.Api.Characters; using Novelly.Api.Tags; using Novelly.Api.Users; namespace Novelly.Api.Novels; public class Novel { public Guid Id { get; set; } = Guid.NewGuid(); public string Title { get; set; } = string.Empty; public string? Author { get; set; } public string? Genre { get; set; } public string? Logline { get; set; } public string? Synopsis { get; set; } public string? Notes { get; set; } public int? TargetWordCount { get; set; } public NovelPhase Phase { get; set; } = NovelPhase.Brainstorming; public Guid? OwnerId { get; set; } public NovellyUser? Owner { get; set; } public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow; public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow; public List Characters { get; set; } = []; public List Chapters { get; set; } = []; public List Tags { get; set; } = []; public List Conversations { get; set; } = []; public List Members { get; set; } = []; } public class NovelEntityTypeConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder entity) { entity.Property(p => p.Title).IsRequired().HasMaxLength(300); entity.Property(p => p.Phase).HasConversion().HasMaxLength(32); entity.HasMany(p => p.Characters).WithOne(c => c.Novel!) .HasForeignKey(c => c.NovelId).OnDelete(DeleteBehavior.Cascade); entity.HasMany(p => p.Chapters).WithOne(c => c.Novel!) .HasForeignKey(c => c.NovelId).OnDelete(DeleteBehavior.Cascade); entity.HasMany(p => p.Tags).WithOne(t => t.Novel!) .HasForeignKey(t => t.NovelId).OnDelete(DeleteBehavior.Cascade); entity.HasMany(p => p.Conversations).WithOne(c => c.Novel!) .HasForeignKey(c => c.NovelId).OnDelete(DeleteBehavior.Cascade); entity.HasMany(p => p.Members).WithOne(m => m.Novel!) .HasForeignKey(m => m.NovelId).OnDelete(DeleteBehavior.Cascade); entity.HasOne(p => p.Owner).WithMany() .HasForeignKey(p => p.OwnerId).OnDelete(DeleteBehavior.Restrict); } }