using Microsoft.EntityFrameworkCore; using GestorFacturas.API.Models; namespace GestorFacturas.API.Data; public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions options) : base(options) { } public DbSet Configuraciones { get; set; } public DbSet Eventos { get; set; } public DbSet Usuarios { get; set; } public DbSet RefreshTokens { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity(entity => { entity.ToTable("Configuraciones"); entity.HasData(new Configuracion { Id = 1, Periodicidad = "Dias", ValorPeriodicidad = 1, HoraEjecucion = "00:00:00", Estado = true, EnEjecucion = false, DBServidor = "TECNICA3", DBNombre = "", DBTrusted = true, RutaFacturas = "", RutaDestino = "", SMTPPuerto = 587, SMTPSSL = true, AvisoMail = false }); }); modelBuilder.Entity(entity => { entity.ToTable("Eventos"); entity.HasIndex(e => e.Fecha); entity.HasIndex(e => e.Tipo); }); // Seed de Usuario Admin // Pass: admin123 modelBuilder.Entity().HasData(new Usuario { Id = 1, Username = "admin", Nombre = "Administrador", PasswordHash = "$2a$11$l5UnZIE8bVWSUhYorVqlW.f0qgvK2zsD8aYDyTRXKjtFwwdiAfAvW" // Hash placeholder, se actualiza al loguear si es necesario o usar uno real }); // Configuración de RefreshToken (Opcional si usas convenciones, pero bueno para ser explícito) modelBuilder.Entity() .HasMany() .WithOne(r => r.Usuario) .HasForeignKey(r => r.UsuarioId) .OnDelete(DeleteBehavior.Cascade); } }