using Marathon.Infrastructure.Persistence.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Marathon.Infrastructure.Persistence.Configurations; internal sealed class SavedStrategyConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("SavedStrategies"); builder.HasKey(s => s.Id); builder.Property(s => s.Id).HasColumnType("TEXT").IsRequired(); // NOCASE so the unique index and the GetByNameAsync lookup both treat names // case-insensitively (ASCII) — "Kelly" and "kelly" are the same preset, and // save-by-name overwrites rather than creating a near-duplicate. builder.Property(s => s.Name).HasColumnType("TEXT").UseCollation("NOCASE").IsRequired(); builder.Property(s => s.StartingBankroll).HasColumnType("TEXT").IsRequired(); builder.Property(s => s.MinScore).HasColumnType("TEXT").IsRequired(); builder.Property(s => s.StakeRule).HasColumnType("INTEGER").IsRequired(); builder.Property(s => s.FlatStake).HasColumnType("TEXT").IsRequired(); builder.Property(s => s.PercentOfBankroll).HasColumnType("TEXT").IsRequired(); builder.Property(s => s.KellyFraction).HasColumnType("TEXT").IsRequired(); builder.Property(s => s.CreatedAt).HasColumnType("TEXT").IsRequired(); // Names are the user-facing identity for save/overwrite, so they must be // unique — the SaveStrategyUseCase upserts by name and the index backstops // any race that would otherwise create a duplicate. builder.HasIndex(s => s.Name) .IsUnique() .HasDatabaseName("IX_SavedStrategies_Name"); } }