using AyCode.Database.ModelBuilders.Profiles;
using AyCode.Database.ModelBuilders.Users;
using AyCode.Interfaces.Addresses;
using AyCode.Interfaces.Messages;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore;

namespace AyCode.Database.DbContexts.Users
{
    public abstract class AcUserDbContextBase<TUser, TProfile, TUserToken, TCompany, TUserToCompany, TAddress, TEmailMessage> : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken, TCompany, TUserToCompany, TAddress, TEmailMessage> 
        where TUser : class, IAcUser<TProfile, TCompany, TUserToCompany, TAddress>
        where TProfile : class, IAcProfile<TAddress>
        where TUserToken : class, IAcUserTokenBase
        where TCompany : class, IAcCompany<TUser, TUserToCompany, TProfile>//IAcServiceProviderBase
        where TUserToCompany : class, IAcUserToCompanyBase
        where TAddress : class, IAcAddress
        where TEmailMessage : class, IAcEmailMessageBase
    {
        public required DbSet<TUser> Users { get; set; }
        public required DbSet<TUserToken> UserTokens { get; set; }
        public DbSet<TAddress> Addresses { get; set; }
        public DbSet<TProfile> Profiles { get; set; }
        public DbSet<TEmailMessage> EmailMessages { get; set; }
        public DbSet<TCompany> Companies { get; set; }

        protected AcUserDbContextBase() : this(string.Empty)
        { }

        protected AcUserDbContextBase(string name) : base(name)
        { }

        protected AcUserDbContextBase(DbContextOptions<DbContext> options, string name) : base(options, name)
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);

            optionsBuilder.UseLazyLoadingProxies(true);
        }

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

            new AcUserEntityTypeDefaultConfiguration<TUser, TProfile, TCompany, TUserToCompany, TAddress>().Configure(modelBuilder.Entity<TUser>());
            new AcProfileEntityTypeDefaultConfiguration<TProfile, TAddress>().Configure(modelBuilder.Entity<TProfile>());

            //new EmailMessageEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<EmailMessage>());
        }
    }
}
