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(); protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // ✅ MANTIDO: índice único do User modelBuilder.Entity() .HasIndex(u => u.Email) .IsUnique(); // ✅ MANTIDO: índice único para evitar duplicar a mesma linha (telefone) modelBuilder.Entity() .HasIndex(x => x.Linha) .IsUnique(); // ✅ MANTIDO: índices do 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); // ========================================================== // ✅ NOVO: MAPEAMENTO DO FATURAMENTO // (evita problema de tabela "BillingClients" vs postgres case) // ========================================================== modelBuilder.Entity(e => { // 🔥 Nome físico fixo da tabela no Postgres e.ToTable("billing_clients"); e.HasKey(x => x.Id); // (opcional, mas bom pra padronizar) e.Property(x => x.Tipo).HasMaxLength(2); e.Property(x => x.Cliente).HasMaxLength(255); // índices úteis para filtros/ordenação e.HasIndex(x => x.Tipo); e.HasIndex(x => x.Cliente); e.HasIndex(x => new { x.Tipo, x.Cliente }); e.HasIndex(x => x.Item); }); } }