using System.Collections.ObjectModel;
using System.Linq;
using Aitex.Core.Util;
using MECF.Framework.Common.Account.Permissions;

namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
    public class RolePermissionTrueFalseMapper : Singleton<RolePermissionTrueFalseMapper>
    {
        public static readonly PermissionMappedType No = new(MenuPermissionEnum.MP_NONE, "NO");
        public static readonly PermissionMappedType Yes = new(MenuPermissionEnum.MP_READ_WRITE, "YES");
        
        #region Properties

        public ObservableCollection<PermissionMappedType> PermissionDictionary { get; } = new()
        {
            No,
            Yes
        };

        #endregion

        #region Methods
        
        public static PermissionMappedType FromMenuPermissionEnum(MenuPermissionEnum perm)
        {
            // 为兼容已存在的权限，将配置为MP_READ的项目更换为MP_READ_WRITE
            if (perm == MenuPermissionEnum.MP_READ)
                perm = MenuPermissionEnum.MP_READ_WRITE;
            
            return Instance.PermissionDictionary.FirstOrDefault(x => x.EnumPermission == perm) ?? No;
        }
        
        public string ToString(MenuPermissionEnum enumPermission)
        {
            foreach (var pd in PermissionDictionary)
            {
                if (pd.EnumPermission == enumPermission)
                {
                    return pd.StringPermission;
                }
            }

            return "";
        }
        
        #endregion
        
        
       

        

       
    }
}
