using GermanApp.Domain.Entities;
using Microsoft.EntityFrameworkCore;
namespace GermanApp.Infrastructure.Data.DbContext;
///
/// Entity Framework Core database context.
/// This is part of the Infrastructure layer.
///
public class AppDbContext : Microsoft.EntityFrameworkCore.DbContext
{
public AppDbContext(DbContextOptions options) : base(options)
{
}
// DbSets for domain entities
public DbSet Lessons { get; set; } = null!;
// Note: Value objects are not stored directly as entities.
// They are owned by entities and stored as part of the entity's data.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Configure Lesson entity
modelBuilder.Entity(builder =>
{
builder.HasKey(l => l.Id);
builder.Property(l => l.Title).IsRequired().HasMaxLength(200);
builder.Property(l => l.Description).IsRequired().HasMaxLength(2000);
builder.Property(l => l.Level).IsRequired();
builder.Property(l => l.CreatedAt).IsRequired();
builder.Property(l => l.UpdatedAt).IsRequired(false);
// Value object: GermanWord would be configured as an owned entity
// builder.OwnsMany(l => l.Words, wordBuilder =>
// {
// wordBuilder.Property(w => w.Value).HasColumnName("WordValue");
// wordBuilder.Property(w => w.Translation).HasColumnName("Translation");
// wordBuilder.Property(w => w.Article).HasColumnName("Article");
// wordBuilder.Property(w => w.PartOfSpeech).HasColumnName("PartOfSpeech");
// });
});
// Seed data (optional) - Note: For EF Core, we need to set properties directly
// In a real application, use migrations or a separate seeding mechanism
// modelBuilder.Entity().HasData(
// new { Id = 1, Title = "Greetings", Description = "Basic German greetings", Level = 1, CreatedAt = DateTime.UtcNow },
// new { Id = 2, Title = "Numbers", Description = "German numbers 1-100", Level = 1, CreatedAt = DateTime.UtcNow },
// new { Id = 3, Title = "Grammar Basics", Description = "Basic German grammar", Level = 2, CreatedAt = DateTime.UtcNow }
// );
}
}