using FAuth.DataBase.Tables;
using Microsoft.EntityFrameworkCore;

namespace FAuth.DataBase
{
    /// <summary>
    /// 数据库
    /// </summary>
    public class FAuthDb:DbContext
    {
        public FAuthDb(DbContextOptions options) : base(options) {
            //Database.EnsureCreatedAsync().Wait();
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder) {
            var mb = modelBuilder;
            mb.Entity<App_RoleGroup>().HasKey(m => new { m.AppId,m.RoleGroupId });
            mb.Entity<RoleGroup_Role>().HasKey(m => new { m.RoleGroupId,m.RoleId });
            mb.Entity<Role_User>().HasKey(m => new { m.RoleId,m.UserId });
            base.OnModelCreating(modelBuilder);
        }

        /// <summary>
        /// 用户
        /// </summary>
        public DbSet<FUser> Users { get; set; }
        /// <summary>
        /// 应用信息
        /// </summary>
        public DbSet<Apps> Apps { get; set; }
        /// <summary>
        /// 角色组信息
        /// </summary>
        public DbSet<RoleGroup> RoleGroups { get; set; }
        /// <summary>
        /// 角色信息
        /// </summary>
        public DbSet<Roles> Roles { get; set; }
        /// <summary>
        /// 应用角色组对应关系
        /// </summary>
        public DbSet<App_RoleGroup> App_RoleGroups { get; set; }
        /// <summary>
        /// 角色组角色对应关系
        /// </summary>
        public DbSet<RoleGroup_Role> RoleGroup_Roles { get; set; }
        /// <summary>
        /// 角色用户对应关系
        /// </summary>
        public DbSet<Role_User> Role_Users { get; set; }
    }
}
