using Microsoft.EntityFrameworkCore;
using NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration;
using NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Power;
using NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Security;
using NetworkResurrector.Api.Domain.Entities;
using NetworkResurrector.Api.Domain.Entities.Security;

namespace NetworkResurrector.Api.Domain.Data.DbContexts
{
    public class NetworkDbContext : DbContext
    {
        public DbSet<Machine> Machines { get; set; }
        public DbSet<Entities.Power.PowerActionConfiguration> PowerActionConfigurations { get; set; }
        public DbSet<UserRoleAuthorization> UserRoleAuthorizations { get; set; }
        public DbSet<PermissionHierarchy> PermissionHierarchies { get; set; }

        public NetworkDbContext(DbContextOptions<NetworkDbContext> options)
            : base(options)
        {
            base.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;
            base.ChangeTracker.AutoDetectChangesEnabled = true;
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.ApplyConfiguration(new MachineConfiguration());
            modelBuilder.ApplyConfiguration(new PowerActionConfiguration());
            modelBuilder.ApplyConfiguration(new PowerActionPerformerConfiguration());
            modelBuilder.ApplyConfiguration(new PowerActionConfigurationEf());
            modelBuilder.ApplyConfiguration(new MachineAgentConfiguration());
            modelBuilder.ApplyConfiguration(new PermissionConfiguration());
            modelBuilder.ApplyConfiguration(new PermissionHierarchyConfiguration());
            modelBuilder.ApplyConfiguration(new UserRoleAuthorizationConfiguration());
        }
    }
}
