using Hncore.Infrastructure.Data;
using Hncore.Infrastructure.DDD;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Data;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Manage.Request;

namespace Hncore.Pass.Manage.Domain  
{
    public class ManagerToPermission  : AggregateRoot<int>, ITenant

    {

        /// <summary>
        /// 用户数据库ID
        /// <summary>
        public override int Id { get; set; }

        /// <summary>
        /// 所属物业ID
        /// <summary>
        public int TenantId { get; set; }

        /// <summary>
        /// 创建时间
        /// <summary>
        public  DateTime CreateTime { get; set; }

        /// <summary>
        /// 更新时间
        /// <summary>
        public  DateTime UpdateTime { get; set; }

        /// <summary>
        /// 创建人ID
        /// <summary>
        public int CreatorId { get; set; }

        /// <summary>
        /// 更新人ID
        /// <summary>
        public int UpdatorId { get; set; }

        /// <summary>
        /// 软删除标记，0.代表正常，1.代表已删除
        /// <summary>
        public   int DeleteTag { get; set; }

        /// <summary>
        /// 管理员id
        /// <summary>
        public int ManagerId { get; set; }  

        /// <summary>
        /// 权限编码
        /// <summary>
        public string PermissionCode  { get; set; }


        /// <summary>
        /// 是否查看
        /// </summary>
        public int AllowView { get; set;  }


        /// <summary>
        /// 是否添加
        /// </summary>
        public int  AllowAdd   { get; set; }


        /// <summary>
        /// 是否修改
        /// </summary>
        public int AllowEdit  { get; set; }


        /// <summary>
        /// 是否删除
        /// </summary>
        public int AllowDel { get; set; }

        public DateTime? ExpiredTime { get; set; }


        /// <summary>
        /// 创建管理员权限关系
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task<ManagerToPermission> Create(RequestBase<EditManagerToPermissionRequest> request,
            IQueryable<ManagerToPermission> queryable)
        {
  
            var ManagerToPermission  = new ManagerToPermission()
            {
                ManagerId = request.Data.ManagerId,
                PermissionCode = request.Data.PermissionCode,
                AllowView = request.Data.AllowView,
                AllowAdd = request.Data.AllowAdd,
                AllowEdit = request.Data.AllowEdit,
                AllowDel = request.Data.AllowDel,
                
                TenantId = request.TenantId,
                CreatorId = request.OperaterId,
                UpdatorId = request.OperaterId,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            };

            return ManagerToPermission;
        }


        /// <summary>
        /// 编辑管理员权限关系
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<ManagerToPermission> Edit(RequestBase<EditManagerToPermissionRequest> request, IQueryable<ManagerToPermission> queryable)
        {

            PermissionCode = request.Data.PermissionCode;
            UpdatorId = request.OperaterId;
            UpdateTime = DateTime.Now;

            return this;
        }



    }
}
