using AyCode.Database.DbContexts;
using AyCode.Interfaces.Addresses;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace AyCode.Database.ModelBuilders.Users;

public class AcUserEntityTypeDefaultConfiguration<TUser, TProfile, TCompany, TUserToCompany, TProfileAddress> : IAcEntityTypeConfiguration<TUser> 
    where TUser : class, IAcUser<TProfile, TCompany, TUserToCompany, TProfileAddress> 
    where TProfile : class, IAcProfile<TProfileAddress>
    where TCompany : class, IAcCompany<TUser, TUserToCompany, TProfile>
    where TUserToCompany : class, IAcUserToCompanyBase
    where TProfileAddress : class, IAcAddress
{
    public virtual void Configure(EntityTypeBuilder<TUser> modelBuilder)
    {
        modelBuilder.BuildEntityToProfileRelation<TUser, TProfile>();
        //modelBuilder.BuildEntityToAddressRelation<TProfileAddress, TProfile, TProfileAddress>();
        modelBuilder.BuildEntityToServiceProviderRelation<TUser, TCompany, TUserToCompany, TProfile>();
    }
}

public class AcCompanyEntityTypeDefaultConfiguration<TCompany, TProfile, TProfileAddress, TUserToCompany, TUser> : IAcEntityTypeConfiguration<TCompany> 
    where TUser : class, IAcUser<TProfile, TCompany, TUserToCompany, TProfileAddress> 
    where TProfile : class, IAcProfile<TProfileAddress>
    where TCompany : class, IAcCompany<TUser, TUserToCompany, TProfile>
    where TUserToCompany : class, IAcUserToCompanyBase
    where TProfileAddress : class, IAcAddress
{
    public virtual void Configure(EntityTypeBuilder<TCompany> modelBuilder)
    {
        modelBuilder.BuildEntityToProfileRelation<TCompany, TProfile>();

        //modelBuilder
        //    .HasMany(e => e.Users)
        //    .WithMany(e => e.ServiceProviders)
        //    .UsingEntity<TUserToCompany>();

        //modelBuilder.Navigation(e => e.Users).AutoInclude();
        modelBuilder.Navigation(e => e.UserToServiceProviders).AutoInclude();
    }
}
