using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using MS.DbContexts.AccountingService;
using MS.DbContexts.AuthService;
using MS.Entities.AccountingService_Models;
using MS.Entities.AuthService_Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace MS.DbContexts
{
    public class AuthContext : DbContext
    {
        public AuthContext(DbContextOptions<AuthContext> options)
          : base(options)
        {
        }
        public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => builder.AddDebug().AddConsole());
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseLoggerFactory(MyLoggerFactory);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ApplyConfiguration(new UserSubIdentitiesMap());
            modelBuilder.ApplyConfiguration(new AspNetUsersMap());
            modelBuilder.ApplyConfiguration(new IdentityUserBusiUnit_M2MMap());
            modelBuilder.Entity<AspNetUserLogins>()
        .HasNoKey();
            modelBuilder.Entity<AspNetUserRoles>()
        .HasNoKey();
            modelBuilder.Entity<AspNetUsers>()
        .Ignore(u => u.AspNetUserLogins);
            modelBuilder.Entity<AspNetUsers>()
        .Ignore(u => u.AspNetUserRoles);
            modelBuilder.Entity<AspNetRoles>()
        .Ignore(r => r.AspNetUserRoles);
            //    modelBuilder.Entity<IdentityUserBusiUnitM2m>()
            //.HasNoKey();
            //    modelBuilder.Entity<AspNetUsers>()
            //.Ignore(u => u.IdentityUserBusiUnitM2m);
       //     modelBuilder.Entity<IdentityUserBusiUnitM2m>()
       //.HasKey(e => new { e.ServiceIdentityUserId, e.BusinessUnitId });
            base.OnModelCreating(modelBuilder);
        }
    }
}
