using Knot.Shared.Infrastructure.Persistence.Entities;
using Microsoft.EntityFrameworkCore;

namespace Knot.Shared.Infrastructure.Persistence;

public class SystemDbContext : DbContext
{
    public SystemDbContext(DbContextOptions<SystemDbContext> options) : base(options) { }

    public DbSet<SystemSetting> Settings => Set<SystemSetting>();
    public DbSet<DailyStat> DailyStats => Set<DailyStat>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.HasDefaultSchema("system");

        modelBuilder.Entity<SystemSetting>(builder =>
        {
            builder.ToTable("Settings");
            builder.HasKey(s => s.Key);
        });

        modelBuilder.Entity<DailyStat>(builder =>
        {
            builder.ToTable("DailyStats");
            builder.HasKey(s => s.Date);
        });
    }
}
