using CloudBuilder.Core.DependencyInjection.EFCore;
using Microsoft.EntityFrameworkCore;
using System.Reflection;

namespace CloudBuilder.AI.Entity
{
    public class CloudBuilderAIRegistEntity : IMasterRegistEntityType<ModelBuilder>
    {
        ///<summary>
        ///注入模块内的所有实体类
        ///</summary>
        ///<param name="builder"></param>
        public void RegistEntity(ModelBuilder builder)
        {
            string _assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
            //注入所有Entity实体类
            AddEntityType(builder, _assemblyName);
            //如果Entity实体类不是单一主键，要单独重写注入
            RegistKeys(builder);
        }

        public void AddEntityType(ModelBuilder builder, string _assemblyName)
        {
            RegistEntityHelper.AddMasterEntityType(builder, _assemblyName);
        }

        ///<summary>
        ///如果存在多个主键的，要在RegistKeys方法注入
        ///builder.Entity<xxxxxxEntity>().HasKey(c => new { c.TableName, c.FieldName });                
        ///builder.Entity<xxxxxxEntity>(eb => { eb.HasNoKey(); });
        ///</summary>
        ///<param name="builder"></param>
        public void RegistKeys(ModelBuilder builder)
        {
            //***BEGIN***


            builder.Entity<AiSentenceViewEntity>(eb => { eb.HasNoKey(); });
            builder.Entity<DmsFolderMapEntity>().HasKey(c => new {c.FolderNameParent,c.FolderNameSon});
            builder.Entity<BookDmsFileViewEntity>(eb => { eb.HasNoKey(); });
            builder.Entity<AiSentenceViewEntity>(eb => { eb.HasNoKey(); });
            builder.Entity<AiSentenceViewEntity>(eb => { eb.HasNoKey(); });
            builder.Entity<AiParagraphViewEntity>(eb => { eb.HasNoKey(); });
            //***END***
        }
    }
}

