namespace Atomx.Common.Constant
{
    public static class Permissions
    {
        public static class Role
        {
            public const string View = "Role.View";
            public const string Create = "Role.Create";
            public const string Edit = "Role.Edit";
            public const string Delete = "Role.Delete";
            public const string Export = "Role.Export";
        }

        public static class User
        {
            public const string View = "User.View";
            public const string Create = "User.Create";
            public const string Edit = "User.Edit";
            public const string Delete = "User.Delete";
            public const string Export = "User.Export";
        }

        public static class Admin
        {
            public const string View = "Admin.View";
            public const string Create = "Admin.Create";
            public const string Edit = "Admin.Edit";
            public const string Delete = "Admin.Delete";
            public const string Export = "Admin.Export";
        }

        private static readonly Dictionary<string, string> PermissionDescriptions = new()
        {
            { "User", "用户管理" },
            { "User.View", "查看用户列表和详情" },
            { "User.Create", "创建新用户" },
            { "User.Edit", "编辑用户信息" },
            { "User.Delete", "删除用户" },
            { "User.Export", "导出用户数据" },
            
            { "Role", "角色管理" },
            { "Role.View", "查看角色列表和详情" },
            { "Role.Create", "创建新角色" },
            { "Role.Edit", "编辑角色信息" },
            { "Role.Delete", "删除角色" },
            { "Role.Export", "导出角色数据" },

            { "System", "系统管理" },
            { "Content", "内容管理" },
            { "Reports", "报表管理" }
        };

        public static List<string> GetAllPermissions()
        {
            return typeof(Permissions)
                .GetNestedTypes().SelectMany(t => t.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy))
            .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(string))
            .Select(fi => (string)fi.GetValue(null)!)
            .ToList();
        }

        public static string GetPermissionDescription(string permission)
        {
            return PermissionDescriptions.ContainsKey(permission) ? PermissionDescriptions[permission] : permission;
        }
    }
}
