using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using MS.Entities.AuthService_Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace MS.DbContexts.AuthService
{
    public class IdentityUserBusiUnit_M2MMap : IEntityTypeConfiguration<IdentityUserBusiUnitM2m>
    {
        public void Configure(EntityTypeBuilder<IdentityUserBusiUnitM2m> entity)
        {
            entity.HasKey(e => new { e.ServiceIdentityUserId, e.BusinessUnitId })
                    .HasName("PK_public.IdentityUserBusiUnit_M2M");

            entity.ToTable("IdentityUserBusiUnit_M2M");

            entity.HasIndex(e => e.BusinessUnitId)
                .HasName("IdentityUserBusiUnit_M2M_IX_BusinessUnitId");

            entity.HasIndex(e => e.ServiceIdentityUserId)
                .HasName("IdentityUserBusiUnit_M2M_IX_ServiceIdentityUserId");

            entity.Property(e => e.ServiceIdentityUserId).HasMaxLength(128);

            entity.HasOne(d => d.BusinessUnit)
                .WithMany(p => p.IdentityUserBusiUnitM2m)
                .HasForeignKey(d => d.BusinessUnitId)
                .HasConstraintName("FK_public.IdentityUserBusiUnit_M2M_public.BusinessUnits_Busines");

            entity.HasOne(d => d.ServiceIdentityUser)
                .WithMany(p => p.IdentityUserBusiUnitM2m)
                .HasForeignKey(d => d.ServiceIdentityUserId)
                .HasConstraintName("FK_public.IdentityUserBusiUnit_M2M_public.AspNetUsers_ServiceId");
        }
    }
}
