using SqlSugar;
using System.ComponentModel;
using Hotline.Permissions;
using Hotline.Share.Dtos.Roles;
using XF.Domain.Repository;

namespace Hotline.Settings
{
    [Description("权限分配")]
    public class SystemAuthority : CreationEntity
    {
        /// <summary>
        /// 角色ID
        /// </summary>
        public string RoleId { get; set; }

        /// <summary>
        /// 角色Code
        /// </summary>
        public string RoleCode { get; set; }

        /// <summary>
        /// 菜单ID
        /// </summary>
        [SugarColumn(ColumnDataType = "json", IsJson = true)]
        public List<PermissionItem> SystemMenuArr { get; set; }

        /// <summary>
        /// 功能点
        /// </summary>
        //[SugarColumn(ColumnDataType = "json", IsJson = true)]
        //public List<string> SystemButtonArr { get; set; }

        public List<string> GetPermissions() => 
            GetPermissionCodes().Select(d => Enum.Parse<EPermission>(d).ToString()).Distinct().ToList();

        public List<string> GetPermissionCodes() =>
            SystemMenuArr.Select(d => d.Code).ToList();
    }
}
