using ControlCenter.Api.Configurations;
using ControlCenter.Api.Entities;
using Microsoft.EntityFrameworkCore;

namespace ControlCenter.Api.Data;

/// <summary>
/// EF Core DbContext for the Control Center database.
/// All table and column names use snake_case via explicit HasColumnName configuration.
/// </summary>
public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }

    public DbSet<Agent> Agents => Set<Agent>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Apply all entity type configurations from the Configurations namespace
        modelBuilder.ApplyConfigurationsFromAssembly(typeof(AgentConfiguration).Assembly);

        // Map the AgentStatus enum to a PostgreSQL enum type named "agent_status"
        // This must be called after ApplyConfigurations to ensure the model is built
        // before the enum mapping is applied.
        modelBuilder.HasPostgresEnum<AgentStatus>();

        base.OnModelCreating(modelBuilder);
    }
}