using Microsoft.EntityFrameworkCore;

public class AppDbContext : DbContext
{
    private readonly IPhiEncryptionService? _phiCrypto;

    public AppDbContext(
        DbContextOptions<AppDbContext> options,
        IPhiEncryptionService? phiCrypto = null) : base(options)
    {
        _phiCrypto = phiCrypto;
    }

    public DbSet<Patient> Patients => Set<Patient>();
    public DbSet<Encounter> Encounters => Set<Encounter>();
    public DbSet<AlertThreshold> AlertThresholds => Set<AlertThreshold>();
    public DbSet<Observation> Observations => Set<Observation>();
    public DbSet<ClinicalAlert> ClinicalAlerts => Set<ClinicalAlert>();
    public DbSet<Order> Orders => Set<Order>();
    public DbSet<OutboxEvent> OutboxEvents => Set<OutboxEvent>();
    public DbSet<ReconciliationAlert> ReconciliationAlerts => Set<ReconciliationAlert>();
    public DbSet<News2Score> News2Scores => Set<News2Score>();
    public DbSet<SepsisBundle> SepsisBundles => Set<SepsisBundle>();
    public DbSet<SepsisBundleElement> SepsisBundleElements => Set<SepsisBundleElement>();
    public DbSet<MedicationAdministration> MedicationAdministrations => Set<MedicationAdministration>();
    public DbSet<GcsScore> GcsScores => Set<GcsScore>();
    public DbSet<SofaScore> SofaScores => Set<SofaScore>();
    public DbSet<QsofaEvaluation> QsofaEvaluations => Set<QsofaEvaluation>();
    public DbSet<ExternalResourceIdentifier> ExternalResourceIdentifiers => Set<ExternalResourceIdentifier>();
    public DbSet<ClinicalUser> ClinicalUsers => Set<ClinicalUser>();
    public DbSet<ClinicalAuditLog> ClinicalAuditLogs => Set<ClinicalAuditLog>();
    public DbSet<PhiAccessLog> PhiAccessLogs => Set<PhiAccessLog>();
    public DbSet<ClinicalSite> ClinicalSites => Set<ClinicalSite>();
    public DbSet<WardGateway> WardGateways => Set<WardGateway>();
    public DbSet<ClinicalSyncBatch> ClinicalSyncBatches => Set<ClinicalSyncBatch>();
    public DbSet<ClinicalSyncConflict> ClinicalSyncConflicts => Set<ClinicalSyncConflict>();
    public DbSet<AlertFeedback> AlertFeedbacks => Set<AlertFeedback>();
    public DbSet<AlertQualityMetric> AlertQualityMetrics => Set<AlertQualityMetric>();
    public DbSet<RefreshToken> RefreshTokens => Set<RefreshToken>();
    public DbSet<SimulationRun> SimulationRuns => Set<SimulationRun>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);

        if (_phiCrypto is not null)
            modelBuilder.ConfigurePhiConverters(_phiCrypto);
    }
}