using Microsoft.EntityFrameworkCore; using line_gestao_api.Models; namespace line_gestao_api.Data; public class AppDbContext : DbContext { public AppDbContext(DbContextOptions options) : base(options) { } public DbSet Users => Set(); // ✅ tabela para espelhar a planilha (GERAL) public DbSet MobileLines => Set(); // ✅ tabela para espelhar a aba MUREG public DbSet MuregLines => Set(); // ✅ tabela para espelhar o FATURAMENTO (PF/PJ) public DbSet BillingClients => Set(); public DbSet UserDatas => Set(); public DbSet VigenciaLines { get; set; } = default!; public DbSet TrocaNumeroLines => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // ========================= // ✅ USER // ========================= modelBuilder.Entity() .HasIndex(u => u.Email) .IsUnique(); // ========================= // ✅ GERAL (MobileLine) // ========================= modelBuilder.Entity() .HasIndex(x => x.Linha) .IsUnique(); // ========================= // ✅ MUREG // ========================= modelBuilder.Entity().HasIndex(x => x.Item); modelBuilder.Entity().HasIndex(x => x.Cliente); modelBuilder.Entity().HasIndex(x => x.ICCID); modelBuilder.Entity().HasIndex(x => x.LinhaNova); // ========================================================== // ✅ FATURAMENTO (BillingClient) - mantém seu mapeamento // ========================================================== modelBuilder.Entity(e => { e.ToTable("billing_clients"); e.HasKey(x => x.Id); e.Property(x => x.Tipo).HasMaxLength(2); e.Property(x => x.Cliente).HasMaxLength(255); e.HasIndex(x => x.Tipo); e.HasIndex(x => x.Cliente); e.HasIndex(x => new { x.Tipo, x.Cliente }); e.HasIndex(x => x.Item); }); // ========================================================== // ✅ VIGÊNCIA (se você quiser índices aqui também, pode manter) // ========================================================== // modelBuilder.Entity().HasIndex(x => x.Cliente); // modelBuilder.Entity().HasIndex(x => x.Linha); // ========================================================== // ✅ TROCA NÚMERO (opcional: índices) // ========================================================== // modelBuilder.Entity().HasIndex(x => x.Cliente); // modelBuilder.Entity().HasIndex(x => x.LinhaAntiga); // modelBuilder.Entity().HasIndex(x => x.LinhaNova); } }