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

namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
    public class RolePermissionMapper : Singleton<RolePermissionMapper>
    {
        public static readonly PermissionMappedType None = new(MenuPermissionEnum.MP_NONE, "NONE");
        public static readonly PermissionMappedType Read = new(MenuPermissionEnum.MP_READ, "READ");
        public static readonly PermissionMappedType ReadWrite = new(MenuPermissionEnum.MP_READ_WRITE, "READ & WRITE");
        
        #region Properties

        public ObservableCollection<PermissionMappedType> PermissionDictionary { get; } = new()
        {
            None,
            Read,
            ReadWrite
        };

        #endregion

        #region Methods

        public static PermissionMappedType FromMenuPermissionEnum(MenuPermissionEnum perm)
        {
            return Instance.PermissionDictionary.FirstOrDefault(x => x.EnumPermission == perm) ?? None;
        }

        public string ToString(MenuPermissionEnum enumPermission)
        {
            foreach (var pd in PermissionDictionary)
            {
                if (pd.EnumPermission == enumPermission)
                {
                    return pd.StringPermission;
                }
            }

            return "";
        }

        #endregion
    }
    
}
