using Deal.Infrastructure.Persistence.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Deal.Infrastructure.Persistence.Configurations; /// /// EF-конфигурация события расхода токенов /// public sealed class TokenUsageEventConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("token_usage_events", "public"); builder.HasKey(x => x.Id); builder.Property(x => x.TenantId).IsRequired(); builder.Property(x => x.At).IsRequired(); builder.Property(x => x.Provider).IsRequired(); builder.Property(x => x.Model).IsRequired(); builder.Property(x => x.Kind).IsRequired(); builder.Property(x => x.PromptTokens).IsRequired(); builder.Property(x => x.CompletionTokens).IsRequired(); builder.Property(x => x.TotalTokens).IsRequired(); builder.Property(x => x.DetailJson).HasColumnType("text"); builder.HasIndex(x => new { x.TenantId, x.At }); builder.HasIndex(x => x.At); builder.HasOne() .WithMany() .HasForeignKey(x => x.TenantId) .OnDelete(DeleteBehavior.Restrict); } }