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

namespace MS.DbContexts.AuthService
{
    public class UserSubIdentitiesMap : IEntityTypeConfiguration<UserSubIdentities>
    {
        public void Configure(EntityTypeBuilder<UserSubIdentities> entity)
        {
            entity.HasIndex(e => e.ServiceIdentityUserId)
                .HasName("UserSubIdentities_IX_ServiceIdentityUser_Id");

            entity.HasIndex(e => new { e.Type, e.Identity })
                .HasName("UserSubIdentities_IX_UserSubIdTypeAndId");

            entity.Property(e => e.Id).HasDefaultValueSql("uuid_generate_v4()");

            entity.Property(e => e.Identity)
                .IsRequired()
                .HasMaxLength(100);

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

            entity.Property(e => e.Type)
                .IsRequired()
                .HasMaxLength(50);

            entity.HasOne(d => d.ServiceIdentityUser)
                .WithMany(p => p.UserSubIdentities)
                .HasForeignKey(d => d.ServiceIdentityUserId)
                .HasConstraintName("FK_public.UserSubIdentities_public.AspNetUsers_ServiceIdentityU");
        }
    }
}
