using IBKRTrader.Modules.CongressTrading.Models;
using Microsoft.EntityFrameworkCore;
namespace IBKRTrader.Modules.CongressTrading.Persistence.Ef;
///
/// EF-Core-Kontext des CongressTrading-Moduls (ct_-Tabellen in derselben MariaDB wie der Core).
///
public class CongressTradingDbContext : DbContext
{
public CongressTradingDbContext(DbContextOptions options) : base(options) { }
public DbSet Members => Set();
public DbSet Trades => Set();
protected override void OnModelCreating(ModelBuilder b)
{
b.Entity(e =>
{
e.ToTable("ct_congressMember");
e.HasKey(x => x.Id);
e.HasIndex(x => x.BioId).IsUnique();
e.Property(x => x.BioId).HasMaxLength(20);
e.Property(x => x.Name).HasMaxLength(200);
e.Property(x => x.Party).HasMaxLength(50);
e.Property(x => x.State).HasMaxLength(50);
e.Property(x => x.Chamber).HasMaxLength(10);
e.Property(x => x.ProfileUrl).HasMaxLength(500);
});
b.Entity(e =>
{
e.ToTable("ct_trade");
e.HasKey(x => x.Id);
e.Ignore(x => x.MemberSnapshot); // transient – nicht persistieren
e.HasIndex(x => x.TradeId).IsUnique();
e.HasIndex(x => x.MemberBioId);
e.HasIndex(x => x.Ticker);
e.HasIndex(x => x.DetailsFetched);
e.Property(x => x.TradeId).HasMaxLength(20);
e.Property(x => x.MemberBioId).HasMaxLength(20);
e.Property(x => x.IssuerName).HasMaxLength(500);
e.Property(x => x.IssuerId).HasMaxLength(20);
e.Property(x => x.Ticker).HasMaxLength(20);
e.Property(x => x.TradeType).HasMaxLength(50);
e.Property(x => x.Chamber).HasMaxLength(20);
e.Property(x => x.Owner).HasMaxLength(50);
e.Property(x => x.Value).HasPrecision(18, 2);
e.Property(x => x.DetailUrl).HasMaxLength(500);
});
}
}