using SharepointToolbox.Core.Helpers;
namespace SharepointToolbox.Core.Models;
///
/// Presentation wrapper around PermissionEntry that adds simplified labels
/// and risk level classification without modifying the immutable source record.
/// Used as the DataGrid ItemsSource when simplified mode is active.
///
public class SimplifiedPermissionEntry
{
/// The original immutable PermissionEntry.
public PermissionEntry Inner { get; }
///
/// Human-readable labels for the permission levels.
/// E.g. "Can edit files and list items" instead of "Contribute".
///
public string SimplifiedLabels { get; }
///
/// The highest risk level across all permission levels on this entry.
/// Used for row-level color coding.
///
public RiskLevel RiskLevel { get; }
///
/// Individual mapping results for each permission level in the entry.
/// Used when detailed breakdown per-role is needed.
///
public IReadOnlyList Mappings { get; }
// ── Passthrough properties for DataGrid binding ──
public string ObjectType => Inner.ObjectType;
public string Title => Inner.Title;
public string Url => Inner.Url;
public bool HasUniquePermissions => Inner.HasUniquePermissions;
public string Users => Inner.Users;
public string UserLogins => Inner.UserLogins;
public string PermissionLevels => Inner.PermissionLevels;
public string GrantedThrough => Inner.GrantedThrough;
public string PrincipalType => Inner.PrincipalType;
public SimplifiedPermissionEntry(PermissionEntry entry)
{
Inner = entry;
Mappings = PermissionLevelMapping.GetMappings(entry.PermissionLevels);
SimplifiedLabels = PermissionLevelMapping.GetSimplifiedLabels(entry.PermissionLevels);
RiskLevel = PermissionLevelMapping.GetHighestRisk(entry.PermissionLevels);
}
///
/// Creates SimplifiedPermissionEntry wrappers for a collection of entries.
///
public static IReadOnlyList WrapAll(
IEnumerable entries)
{
return entries.Select(e => new SimplifiedPermissionEntry(e)).ToList();
}
}